Introduction

Spenza provides various APIs to manage the mobile subscriptions offered in the Spenza marketplace. This document provides the information required to interact with Spenza APIs.

Authentication Headers

All API endpoints (except the authentication endpoint) require a Bearer token in the Authorization header. You must first obtain this token using the Authentication API.

Required Headers
Header Value Description
Authorization Bearer YOUR_TOKEN The access token obtained from the Authentication API
Content-Type application/json All requests must send and receive JSON data
Example Headers
Authorization: Bearer eyJhbGciOiJ...
Content-Type: application/json

Note: Replace YOUR_TOKEN with the actual access token received from the Authentication API.

Authentication

All API calls require authentication using a Bearer Token. You must first obtain this token using the Authenticate API.

POST /api/v1/authenticate

Request Body

{
    "key": "api-key",
    "secret": "api-secret"
}

Required Fields

Field Type Description
key string Your API key
secret string Your API secret

Response


    {
        "message": "Authentication Success.",
        "accessToken": "Your Auth Token for other APIs.",
        "expiration": "token expiration time"
    }
    

Get Sim by ICCID

GET /api/v1/sim-by-iccid

Request Body

{
    "ICCID": "9999967890123456789"
}

Required Fields

Field Type Description
ICCID string The ICCID of the SIM card

Response

{
    "message": "Success.",
    "simInfo": {
        "status": {
            "user": "Assigned",
            "device": "Assigned"
        },
        "operator": {
            "custNbr": null
        },
        "ICCID": "9999967890123456784",
        "activationCode": "",
        "source": "Other",
        "isDeleted": false,
        "recommendedPlan": "60af49af21647e2ca0b15f51",
        "_id": "632808a8e85110002e3ae629",
        "network": "T-Mobile",
        "Operator": "T-Mobile",
        "phoneNumber": "78993093857",
        "group": "63280750e85110002e3ae624",
        "account": "63280446e85110002e3ae54e",
        "phoneLineStatus": "ACTIVATED"
    }
}

Get Plan By planId

GET /api/v1/plan-by-id

Request Parameters

planId: "AT0001"

Required Fields

Field Type Description
planId string Unique identifier for the plan

Purchase Plan

POST /api/v1/purchase-plan

Request Body

{
    "ICCID": "8901260853182965429",
    "productId": "product1",
    "activateNow": true,
    "scheduledDate": "2024-04-20"
}

Required Fields

Field Type Description
ICCID string The ICCID of the SIM card
productId string The ID of the plan to purchase
activateNow boolean Whether to activate the plan immediately
scheduledDate string Date to schedule activation (YYYY-MM-DD format)

Response

{
    "message": "Success.",
    "subscription": {
        "stripe": {
            "subId": "sub_1LkKThAq7JKDyJICNJ3l1WWv",
            "scheduleId": null,
            "price": null
        },
        "operatorRes": {
            "MDN": null,
            "description": null
        },
        "planName": "EXPLAN_100",
        "planCode": "EXPLAN_001",
        "status": "ACTIVE",
        "initiatedDate": "2022-08-21T04:24:06.473Z",
        "startDate": "2022-08-21T04:24:05.000Z",
        "endDate": "2022-11-21T04:24:05.000Z",
        "scheduledDate": "2022-09-20T00:00:00.000Z",
        "cancelledDate": null,
        "autoTopUp": true,
        "subId": "1663734246474",
        "Operator": "T-Mobile",
        "network": "T-Mobile",
        "orderId": "1739-597673-2114"
    }
}

Activate Subscription

PUT /api/v1/activate-subscription

Request Body

{
    "ICCID": "8901260853182965429",
    "productId": "product1"
}

Required Fields

Field Type Description
ICCID string The ICCID of the SIM card
productId string The ID of the plan to activate

Response

{
    "message": "Success",
    "subscription": {
        "stripe": {
            "subId": "sub_1LkKThAq7JKDyJICNJ3l1WWv",
            "scheduleId": null,
            "price": null
        },
        "operatorRes": {
            "MDN": null,
            "description": null
        },
        "planName": "EXPLAN_101",
        "planCode": "EXPLAN_003",
        "status": "ACTIVE",
        "initiatedDate": "2022-08-21T04:24:06.473Z",
        "startDate": "2022-08-21T04:24:05.000Z",
        "endDate": "2022-11-21T04:24:05.000Z",
        "scheduledDate": "2022-09-20T00:00:00.000Z",
        "autoTopUp": true,
        "subId": "1663734246474",
        "Operator": "T-Mobile",
        "network": "T-Mobile",
        "orderId": "1739-597673-2114"
    }
}

Cancel Subscription

POST /api/v1/cancel-subscription

Request Body

{
    "ICCID": "9999967890123456789"
}

Required Fields

Field Type Description
ICCID string The ICCID of the SIM card

Response

{
    "message": "Subscription Cancelled.",
    "subscription": {
        "stripe": {
            "subId": "sub_1LkKThAq7JKDyJICNJ3l1WWv",
            "scheduleId": null,
            "price": null
        },
        "operatorRes": {
            "MDN": null,
            "description": null
        },
        "planName": "EXPLAN_100",
        "planCode": "EXPLAN_001",
        "status": "CANCELLED",
        "initiatedDate": "2022-08-21T04:24:06.473Z",
        "startDate": "2022-08-21T04:24:05.000Z",
        "endDate": "2022-11-21T04:24:05.000Z",
        "scheduledDate": "2022-09-20T00:00:00.000Z",
        "autoTopUp": true,
        "subId": "1663734246474",
        "Operator": "T-Mobile",
        "network": "T-Mobile",
        "orderId": "1739-597673-2114"
    }
}

Get Usage

POST /api/v1/telco/getUsage

Request Body

{
    "subId": "1745863440782"
}

Required Fields

Field Type Description
subId string The ID of the subscription (found in subId field of subscription object)

Response

{
    "result": {
        "usageData": 0,
        "usageCalls": 0,
        "usageSms": 0,
        "usageUpdatedAt": 1747223324287,
        "telcoStatus": "ACTIVATED",
        "usageDataConverted": {
            "format": "B",
            "value": 0
        },
        "network": "Verizon",
        "networkCode": "Verizon"
    }
}

Get Subscription by ICCID

GET /api/v1/subscription-by-iccid

Request Body

{
    "ICCID": "9999967890123456789"
}

Required Fields

Field Type Description
ICCID string The ICCID of the SIM card

Response

{
    "message": "Success.",
    "subscription": {
        "stripe": {
            "subId": "sub_1LkKThAq7JKAyJICNJ3l1WWv",
            "scheduleId": null,
            "price": null
        },
        "operatorRes": {
            "MDN": null,
            "description": null
        },
        "planName": "T-Mobile100",
        "planCode": "T-Mobile0001",
        "status": "Pending",
        "initiatedDate": "2022-09-21T04:24:06.473Z",
        "startDate": "2022-09-21T04:24:05.000Z",
        "endDate": "2022-10-21T04:24:05.000Z",
        "scheduledDate": "2022-09-20T00:00:00.000Z",
        "cancelledDate": null,
        "autoTopUp": true,
        "subId": "1663734246473",
        "Operator": "T-Mobile",
        "network": "T-Mobile",
        "sim": "632a916b961e53002e1298d7",
        "account": "63280446e85110002e3ae54e",
        "orderId": "1339-597673-2114"
    }
}

Renew Phone Number

POST /api/v1/renew-phone-number

Requests a new phone number for the specified SIM card. This endpoint is rate-limited based on your plan configuration.

Request Body

{
    "ICCID": "9999967890123456789"
}

Required Fields

Field Type Description
ICCID string The ICCID of the SIM card

Rate Limiting & IP Restrictions

Monthly Rate Limits: This endpoint is subject to monthly rate limits based on your plan configuration. The limit is defined in the plan's apiLimits.renewPhoneNumber property. If no limit is set, all requests are allowed.

IP Tracking: All requests are logged with the originating IP address from the x-forwarded-for header or connection IP. IP addresses are monitored for security and auditing purposes.

Response

{
    "message": "Request placed successfully, new number will be assigned soon"
}

Error Codes

HTTP Code Message Description
400 Missing Fields Required fields are missing in the request
400 Invalid API Credentials The provided API credentials are invalid
400 Plan Not Found The requested plan does not exist
400 Sim Not Found The requested SIM does not exist
400 Subscription Not Found The requested subscription does not exist
429 Rate Limit Exceeded Monthly rate limit exceeded for API requests
401 Unauthorized Invalid or missing authentication token
403 Forbidden Access denied or insufficient permissions
500 Internal Server Error Something went wrong at our end

Authentication Example

# Request
# First, get your authentication token
$ curl \
    -X POST 'https://api.spenza.com/api/v1/authenticate' \
    -H 'Content-Type: application/json' \
    -d '{
    "key": "api-key",
    "secret": "api-secret"
}'
# Response
{
    "message": "Authentication Success.",
    "accessToken": "Your Auth Token for other APIs.",
    "expiration": "token expiration time"
}
# Example Usage with Token
# Use the received token in subsequent API calls
$ curl \
    -X GET 'https://api.spenza.com/api/v1/sim-by-iccid' \
    -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "ICCID": "9999967890123456789"
}'
# Error Responses
# Missing Fields
{
    "errors": [{
        "message": "Api Key and Secrets are Required Fields.",
        "fields": ["key", "secret"]
    }]
}

# Missing field key
{
    "errors": [{
        "message": "Api Key is Required Field.",
        "fields": ["key"]
    }]
}

# Missing field secret
{
    "errors": [{
        "message": "Api Secret is Required Field.",
        "fields": ["secret"]
    }]
}

# Invalid API Credentials
{
    "errors": [{
        "message": "Invalid Api Credentials."
    }]
}

# Internal Server Error
{
    "errors": [{
        "message": "Something is Wrong at our end. Our Engineers are being Notified."
    }]
}

Get SIM

# Request
# Retrieve SIM information using ICCID
$ curl \
    -X GET 'https://api.spenza.com/api/v1/sim-by-iccid' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "ICCID": "9999967890123456789"
}'
# Response
{
    "message": "Success.",
    "simInfo": {
        "status": {
            "user": "Assigned",
            "device": "Assigned"
        },
        "operator": {
            "custNbr": null
        },
        "ICCID": "9999967890123456784",
        "activationCode": "",
        "source": "Other",
        "isDeleted": false,
        "recommendedPlan": "60af49af21647e2ca0b15f51",
        "_id": "632808a8e85110002e3ae629",
        "network": "T-Mobile",
        "Operator": "T-Mobile",
        "phoneNumber": "78993093857",
        "group": "63280750e85110002e3ae624",
        "account": "63280446e85110002e3ae54e",
        "phoneLineStatus": "ACTIVATED"
    }
}
# Error Responses
# Missing field ICCID
{
    "errors": [{
        "message": "ICCID is required field.",
        "field": "ICCID"
    }]
}

# Internal Server Error
{
    "errors": [{
        "message": "Something is Wrong at our end. Our Engineers are being Notified."
    }]
}

Get Plan

# Request
# Retrieve plan information using planId
$ curl \
    -X GET 'https://api.spenza.com/api/v1/plan-by-id' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "planId": "AT0001"
}'
# Response
{
    "message": "Success.",
    "plan": {
        "stripe": {
            "price": "price_1LgUXYAq7JKAyJICWrRooGBI"
        },
        "productName": "AT&T100",
        "category": "PLANS",
        "Operator": "AT&T",
        "network": "AT&T",
        "zone": "US",
        "validityDays": 30,
        "dataMB": 10,
        "speed": "4G",
        "price": 10,
        "inStock": 0,
        "durationType": "Monthly",
        "isDeleted": false,
        "_id": "63184df1203d4994052869f7",
        "description": "AT&T Plan 1",
        "productId": "AT0001",
        "feature": []
    }
}
# Error Responses
# Missing field planId
{
    "errors": [{
        "message": "Plan Id is Required.",
        "field": "planId"
    }]
}

# Plan Not Found
{
    "errors": [{
        "message": "Plan Not Found."
    }]
}

# Internal Server Error
{
    "errors": [{
        "message": "Something is Wrong at our end. Our Engineers are being Notified."
    }]
}

Purchase Plan

# Request
# Purchase a plan using ICCID, productId and schedule info
$ curl \
    -X POST 'https://api.spenza.com/api/v1/purchase-plan' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "ICCID": "8901260853182965429",
    "productId": "product1",
    "activateNow": true,
    "scheduledDate": "2024-04-20"
}'
# Response
{
    "message": "Success.",
    "subscription": {
        "stripe": {
            "subId": "sub_1LkKThAq7JKDyJICNJ3l1WWv",
            "scheduleId": null,
            "price": null
        },
        "operatorRes": {
            "MDN": null,
            "description": null
        },
        "planName": "EXPLAN_100",
        "planCode": "EXPLAN_001",
        "status": "ACTIVE",
        "initiatedDate": "2022-08-21T04:24:06.473Z",
        "startDate": "2022-08-21T04:24:05.000Z",
        "endDate": "2022-11-21T04:24:05.000Z",
        "scheduledDate": "2022-09-20T00:00:00.000Z",
        "cancelledDate": null,
        "autoTopUp": true,
        "subId": "1663734246474",
        "Operator": "T-Mobile",
        "network": "T-Mobile",
        "orderId": "1739-597673-2114"
    }
}
# Error Responses
# Missing field ICCID
{
    "errors": [{
        "message": "ICCID Key is Required Field.",
        "fields": ["ICCID"]
    }]
}

# Missing field productId
{
    "errors": [{
        "message": "productId is Required Field.",
        "fields": ["productId"]
    }]
}

# Missing field activateNow
{
    "errors": [{
        "message": "activateNow is Required Field.",
        "fields": ["activateNow"]
    }]
}

# Missing field scheduledDate
{
    "errors": [{
        "message": "scheduledDate is Required Field. Format:(YYYY-MM-DD)",
        "fields": ["scheduledDate"]
    }]
}

# Plan Not Found
{
    "errors": [{
        "message": "Plan Not Found."
    }]
}

# Operator Mismatch
{
    "errors": [{
        "message": "Sim Is Not Compatible. Please check Plan Operator and Sim Operator."
    }]
}

# Active Subscription Exists
{
    "errors": [{
        "message": "Sim Already has an Active Subscription."
    }]
}

# Internal Server Error
{
    "errors": [{
        "message": "Something Went Wrong at our End. Our Engineers are being Notified about this Error."
    }]
}

Activate Subscription

# Request
# Activate a purchased plan
$ curl \
    -X PUT 'https://api.spenza.com/api/v1/activate-subscription' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "ICCID": "8901260853182965429",
    "productId": "product1"
}'
# Response
{
    "message": "Success",
    "subscription": {
        "stripe": {
            "subId": "sub_1LkKThAq7JKDyJICNJ3l1WWv",
            "scheduleId": null,
            "price": null
        },
        "operatorRes": {
            "MDN": null,
            "description": null
        },
        "planName": "EXPLAN_101",
        "planCode": "EXPLAN_003",
        "status": "ACTIVE",
        "initiatedDate": "2022-08-21T04:24:06.473Z",
        "startDate": "2022-08-21T04:24:05.000Z",
        "endDate": "2022-11-21T04:24:05.000Z",
        "scheduledDate": "2022-09-20T00:00:00.000Z",
        "autoTopUp": true,
        "subId": "1663734246474",
        "Operator": "T-Mobile",
        "network": "T-Mobile",
        "orderId": "1739-597673-2114"
    }
}
# Error Responses
# Missing field ICCID
{
    "errors": [{
        "message": "ICCID is Required Field.",
        "fields": ["ICCID"]
    }]
}

# Missing field productId
{
    "errors": [{
        "message": "productId is Required Field.",
        "fields": ["productId"]
    }]
}

# Plan Not Found
{
    "errors": [{
        "message": "Plan Not Found."
    }]
}

# Sim Not Found
{
    "errors": [{
        "message": "Sim Not Found."
    }]
}

# Subscription Not Found
{
    "errors": [{
        "message": "Subscription Not Found."
    }]
}

# Internal Server Error
{
    "errors": [{
        "message": "Something is Wrong at our end. Our Engineers are being Notified."
    }]
}

Cancel Subscription

# Request
# Cancel an active subscription
$ curl \
    -X POST 'https://api.spenza.com/api/v1/cancel-subscription' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "ICCID": "9999967890123456789"
}'
# Response
{
    "message": "Subscription Cancelled.",
    "subscription": {
        "stripe": {
            "subId": "sub_1LkKThAq7JKDyJICNJ3l1WWv",
            "scheduleId": null,
            "price": null
        },
        "operatorRes": {
            "MDN": null,
            "description": null
        },
        "planName": "EXPLAN_100",
        "planCode": "EXPLAN_001",
        "status": "CANCELLED",
        "initiatedDate": "2022-08-21T04:24:06.473Z",
        "startDate": "2022-08-21T04:24:05.000Z",
        "endDate": "2022-11-21T04:24:05.000Z",
        "scheduledDate": "2022-09-20T00:00:00.000Z",
        "autoTopUp": true,
        "subId": "1663734246474",
        "Operator": "T-Mobile",
        "network": "T-Mobile",
        "orderId": "1739-597673-2114"
    }
}
# Error Responses
# Missing field ICCID
{
    "errors": [{
        "message": "ICCID is required field.",
        "fields": ["ICCID"]
    }]
}

# Sim Not Found
{
    "errors": [{
        "message": "Sim Not Found."
    }]
}

# Subscription Not Found
{
    "errors": [{
        "message": "Subscription Not Found."
    }]
}

# Internal Server Error
{
    "errors": [{
        "message": "Something is Wrong at our end. Our Engineers are being Notified."
    }]
}

Get Subscription

# Request
# Retrieve subscription by ICCID
$ curl \
    -X GET 'https://api.spenza.com/api/v1/subscription-by-iccid' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "ICCID": "9999967890123456789"
}'
# Response
{
    "message": "Success.",
    "subscription": {
        "stripe": {
            "subId": "sub_1LkKThAq7JKAyJICNJ3l1WWv",
            "scheduleId": null,
            "price": null
        },
        "operatorRes": {
            "MDN": null,
            "description": null
        },
        "planName": "T-Mobile100",
        "planCode": "T-Mobile0001",
        "status": "Pending",
        "initiatedDate": "2022-09-21T04:24:06.473Z",
        "startDate": "2022-09-21T04:24:05.000Z",
        "endDate": "2022-10-21T04:24:05.000Z",
        "scheduledDate": "2022-09-20T00:00:00.000Z",
        "cancelledDate": null,
        "autoTopUp": true,
        "subId": "1663734246473",
        "Operator": "T-Mobile",
        "network": "T-Mobile",
        "sim": "632a916b961e53002e1298d7",
        "account": "63280446e85110002e3ae54e",
        "orderId": "1339-597673-2114"
    }
}
# Error Responses
# Missing field ICCID
{
    "errors": [{
        "message": "ICCID is required field.",
        "field": "ICCID"
    }]
}

# Sim Not Found
{
    "errors": [{
        "message": "Sim Not Found."
    }]
}

# Subscription Not Found
{
    "errors": [{
        "message": "Subscription Not Found."
    }]
}

# Internal Server Error
{
    "errors": [{
        "message": "Something Went Wrong at our End. Our Engineers are being Notified about this Error."
    }]
}

Get Usage

# Request
# Retrieve the usage of a Sim
$ curl \
    -X POST 'https://api.spenza.com/api/v1/telco/getUsage' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "subId": "1745863440782"
}'
# Response
{
    "result": {
        "usageData": 0,
        "usageCalls": 0,
        "usageSms": 0,
        "usageUpdatedAt": 1747223324287,
        "telcoStatus": "ACTIVATED",
        "usageDataConverted": {
            "format": "B",
            "value": 0
        },
        "network": "Verizon",
        "networkCode": "Verizon"
    }
}
# Error Responses
# Missing field subId
{
    "errors": [{
        "message": "Subscription Id is a Required Field.",
        "fields": ["subId"]
    }]
}

# No Active Invoice
{
    "errors": [{
        "message": "Subscription Don't have any Active Invoices."
    }]
}

# Internal Server Error
{
    "errors": [{
        "message": "Something is Wrong at our end. Our Engineers are being Notified."
    }]
}

Renew Phone Number

# Request
# Request a new phone number for a SIM card
$ curl \
    -X POST 'https://api.spenza.com/api/v1/renew-phone-number' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
    "ICCID": "9999967890123456789"
}'
# Response
{
    "message": "Request placed successfully, new number will be assigned soon"
}
# Error Responses
# Missing field ICCID
{
    "errors": [{
        "message": "ICCID is required field.",
        "fields": ["ICCID"]
    }]
}

# Subscription Not Found
{
    "errors": [{
        "message": "Subscription Not Found. Please Create an Active Subscription First."
    }]
}

# Rate Limit Exceeded
{
    "errors": [{
        "message": "Monthly rate limit exceeded for renew phone number requests."
    }]
}

# Internal Server Error
{
    "error": "Something went wrong"
}