Developer Guide

PieSms SMS API

Use the PieSms REST API to send SMS messages and check SMS credit balance. Authenticate requests with your API key and secret, then submit JSON payloads to the endpoints below.

Base URL

https://piesmsapi.pienet.co.tz

Authentication

Basic Auth

Content Type

application/json

Getting API Credentials

  1. Create your PieSms account and verify it.
  2. Log in to your dashboard.
  3. Open `Settings` and go to `Account Credentials`.
  4. Generate your API key and secret.
  5. Store the secret safely because it is shown only once.
  6. Use the generated credentials for Basic Authentication.
POST

Send SMS

https://piesmsapi.pienet.co.tz/v1/send

Headers

FieldTypeDescription
AuthorizationstringBasic authentication header built from api_key:secret_key.
Content-TypestringUse application/json.

Request Body

FieldTypeDescription
source_addrstringSender ID or source address. If text, it should be active on the portal and within the allowed character limit.
schedule_timestringOptional scheduled send time. Format: yyyy-mm-dd hh:mm
encodingstringMessage encoding flag. Use the value expected by your SMS setup, for example 0.
messagestringSMS content to be delivered.
recipientsarrayList of recipients. Each item should contain recipient_id and dest_addr.
recipient_idstring | numberUnique recipient reference returned back in delivery-related handling.
dest_addrstringDestination mobile number in international format, for example 255700000001. Do not include +.

Example Request Body

{
  "source_addr": "INFO",
  "schedule_time": "",
  "encoding": "0",
  "message": "Hello world",
  "recipients": [
    {
      "recipient_id": 1,
      "dest_addr": "255700000001"
    },
    {
      "recipient_id": 2,
      "dest_addr": "255700000002"
    }
  ]
}

Example Response

{
  "successful": true,
  "request_id": 67,
  "code": 100,
  "message": "Message Submitted Successfully",
  "valid": 1,
  "invalid": 0,
  "duplicates": 0
}
GET

Check Balance

https://piesmsapi.pienet.co.tz/v1/balance

Headers

FieldTypeDescription
AuthorizationstringBasic authentication header built from api_key:secret_key.
Content-TypestringUse application/json.

Example Response

{
  "data": {
    "credit_balance": 100
  }
}

Authentication Example

Use HTTP Basic Authentication where the username is your API key and the password is your secret key.

Authorization: Basic base64(api_key:secret_key)

Code Samples

cURL

curl -X POST "https://piesmsapi.pienet.co.tz/v1/send" \
  -H "Authorization: Basic <base64_api_key_colon_secret_key>" \
  -H "Content-Type: application/json" \
  -d '{
  "source_addr": "INFO",
  "schedule_time": "",
  "encoding": "0",
  "message": "Hello world",
  "recipients": [
    {
      "recipient_id": 1,
      "dest_addr": "255700000001"
    },
    {
      "recipient_id": 2,
      "dest_addr": "255700000002"
    }
  ]
}'

JavaScript

const apiKey = "your_api_key";
const secretKey = "your_secret_key";

const payload = {
  "source_addr": "INFO",
  "schedule_time": "",
  "encoding": "0",
  "message": "Hello world",
  "recipients": [
    {
      "recipient_id": 1,
      "dest_addr": "255700000001"
    },
    {
      "recipient_id": 2,
      "dest_addr": "255700000002"
    }
  ]
};

fetch("https://piesmsapi.pienet.co.tz/v1/send", {
  method: "POST",
  headers: {
    Authorization: "Basic " + btoa(apiKey + ":" + secretKey),
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
})
  .then((response) => response.json())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

PHP

<?php
$apiKey = "your_api_key";
$secretKey = "your_secret_key";

$payload = {
  "source_addr" => "INFO",
  "schedule_time" => "",
  "encoding" => "0",
  "message" => "Hello world",
  "recipients" => [
    {
      "recipient_id" => 1,
      "dest_addr" => "255700000001"
    },
    {
      "recipient_id" => 2,
      "dest_addr" => "255700000002"
    }
  ]
};

$ch = curl_init("https://piesmsapi.pienet.co.tz/v1/send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Authorization: Basic " . base64_encode($apiKey . ":" . $secretKey),
  "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>