9BITS DEVELOPER CENTRE
  • 9bits Developer Center
  • MESSAGING
    • A2P SMS
      • Overview
      • Start sending A2P SMS
      • Getting Started
      • REST API
        • Overview
        • Batches
        • Delivery Reports
          • Retrieve a delivery report
        • Webhooks
      • SMPP
        • Connectivity
        • Sending Messages
        • Message Encoding
        • SMPP Error Codes
    • Two-Way SMS
      • Overview
      • Start receiving Two-Way SMS
      • Start sending Two-Way SMS
      • Getting Started
      • REST API
        • Overview
        • Webhooks
  • VOICE
    • Voice Messaging API
      • Overview
      • The Call Object
      • Send a voice message
    • SIP Trunking
      • Overview
      • Technical Details
Powered by GitBook
On this page
  • Send SMS
  • Example
  • Receive SMS
  • Example
  • SMS REST formats and conventions
  • JSON
  1. MESSAGING
  2. Two-Way SMS
  3. REST API

Overview

Send and Receive SMS through a single connection for timely and cost-efficient communication using the 9bits API.

Send SMS

Example

Here is an example of the SMS that should be sent to 9bits endpoint. This example is written in Python.

import requests

api_token = "{YOUR_API_Token}"
url = f"https://app.9bits.net:2081/ng/v1/sendsms"

# Define the payload data in a Python dictionary
data = {
    "from": "48974",
    "to": "2348020000000",
    "message": "When was the last time you went to the cinema?",
    "session_id": "67543uhn3",
    "sent_date": "2024-01-02T23:50:37.000000Z"
}

# Define headers with authorization and content type
headers = {
    "Authorization": f"Bearer {api_token}",
    "Content-Type": "application/json"
}

# Send the POST request
response = requests.post(url, json=data, headers=headers)

# Check the response
if response.status_code == 200:
    print("Request was successful.")
    print(response.json())
else:
    print(f"Request failed with status code: {response.status_code}")
    print(response.text)

Receive SMS

Example

Here is an example of the SMS that would be delivered to your URL. This example is written in Python.

import requests

url = f"{{ client_url }}"

# Define the payload data in a Python dictionary
data = {
    "type": "two-way sms"
    "telco": "mtn",
    "from": "2348020000000",
    "to": "48974",
    "message": "When was the last time you went to the cinema?",
    "session_id": "67543uhn3",
    "sent_date": "2024-01-02T23:50:37.000000Z"
}

# Define headers with authorization and content type
headers = {
    "Authorization": f"Bearer {api_token}",
    "Content-Type": "application/json"
}

# Send the POST request
response = requests.post(url, json=data, headers=headers)

# Check the response
if response.status_code == 200:
    print("Request was successful.")
    print(response.json())
else:
    print(f"Request failed with status code: {response.status_code}")
    print(response.text)

SMS REST formats and conventions

JSON

JSON (appplication/json) is the content type of both requests and responses unless otherwise specified.

Your response to our POST request should be a valid JSON.

Phone numbers (MSISDN)

MSISDNs (phone numbers) would always be delivered to you in international format.

Phone numbers will be sent with or without a leading + (for example, +2348020000000 or 2348020000000).

PreviousREST APINextWebhooks

Last updated 17 days ago