# How to send SMS from code: Python, PHP, Node.js, Java, Go and C# with one REST call

> Sending an SMS from code is one authenticated HTTPS POST: a Bearer token, a JSON body with sender ID, destination number, message and message type, and a message ID back. Here is the same request in Python, PHP, Node.js, Java, Go and C#, plus error handling and production advice.

- Canonical URL: https://www.broadnet.me/blog/send-sms-api-python-php-nodejs-java-csharp
- Language: en
- Last updated: 2026-09-30
- Publisher: BroadNet (https://www.broadnet.me)

- Published: 2026-09-28
- Author: BroadNet Editorial Team

To send an SMS from code, make one HTTPS POST to https://api.broadnet.me/sms/sendSms with an Authorization: Bearer header and a JSON body containing senderId, destinationNumber, message and messageType. A successful call returns HTTP 200 with the message ID as the response body; the delivery result arrives later as a delivery receipt (DLR) to your webhook. Every language below uses only its standard HTTP library; the one official SDK is for TypeScript and Node.js.

## Key takeaways

- Endpoint: POST https://api.broadnet.me/sms/sendSms, JSON body, Bearer token.
- Required fields: senderId, destinationNumber (international format without the plus sign), message, messageType (TEXT).
- Response: 200 with the message ID; keep it to match delivery receipts.
- Errors: a missing or invalid token gets a 401 from the gateway; API errors return status, error, message, errorCode and requestUri.
- One official SDK: @broadnet/cpaas-sdk for TypeScript/Node.js; generate clients for other languages from the OpenAPI spec.

## What do you need before you send?

- An access token from your BroadNet account, kept in an environment variable (BROADNET_TOKEN below), never in source code or a mobile app.
- A sender ID that is allowed for the destination country; some countries require registration first.
- A destination number in international format, for example 447700900123 (a fictional UK number).

Test access comes from our engineers: request it and you get test credentials within one business day, and the first test message usually goes out about five minutes after that. The [quickstart](https://www.broadnet.me/developers/quickstart) walks through it.

## What does the request look like?

Here is the request with cURL. Every example below sends the same JSON body.

```
curl -X POST https://api.broadnet.me/sms/sendSms \
  -H "Authorization: Bearer $BROADNET_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "senderId": "BroadNet",
    "destinationNumber": "447700900123",
    "message": "Your verification code is 482913",
    "messageType": "TEXT"
  }'

# 200 OK → response body is the message ID, e.g. 2603121407537573731
```

## How do you send an SMS with Python?

With the requests library, the json= argument sets the Content-Type header for you.

```
import os, requests

r = requests.post(
    "https://api.broadnet.me/sms/sendSms",
    headers={"Authorization": f"Bearer {os.environ['BROADNET_TOKEN']}"},
    json={
        "senderId": "BroadNet",
        "destinationNumber": "447700900123",
        "message": "Your verification code is 482913",
        "messageType": "TEXT",
    },
)

print(r.status_code, r.text)  # message ID
```

## How do you send an SMS with PHP?

PHP's curl extension is enough; no package is needed.

```
<?php
$ch = curl_init("https://api.broadnet.me/sms/sendSms");
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => [
        "Authorization: Bearer " . getenv("BROADNET_TOKEN"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS     => json_encode([
        "senderId"          => "BroadNet",
        "destinationNumber" => "447700900123",
        "message"           => "Your verification code is 482913",
        "messageType"       => "TEXT",
    ]),
]);

$messageId = curl_exec($ch);
echo $messageId;
```

## How do you send an SMS with Node.js?

Node.js 18 and later have fetch built in:

```
// Node.js 18+ (fetch)
const res = await fetch("https://api.broadnet.me/sms/sendSms", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.BROADNET_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    senderId: "BroadNet",
    destinationNumber: "447700900123",
    message: "Your verification code is 482913",
    messageType: "TEXT",
  }),
});

console.log(await res.text()); // message ID
```

Or use the official TypeScript/Node.js SDK, @broadnet/cpaas-sdk:

```
// npm install @broadnet/cpaas-sdk axios
import { Configuration, SMSSMSApi } from "@broadnet/cpaas-sdk";

const sms = new SMSSMSApi(
  new Configuration({
    basePath: "https://api.broadnet.me",
    accessToken: process.env.BROADNET_TOKEN!,
  }),
);

const res = await sms.smsSendsmsPost({
  sMSSmsRequest: {
    senderId: "BroadNet",
    destinationNumber: "447700900123",
    message: "Your verification code is 482913",
    messageType: "TEXT",
  },
});

console.log(res.data); // message ID
```

## How do you send an SMS with Java?

Java 11 and later include java.net.http.HttpClient:

```
// Java 11+ — java.net.http is built in, nothing to install
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class SendSms {
    public static void main(String[] args) throws Exception {
        String json = "{"
            + "\"senderId\": \"BroadNet\", "
            + "\"destinationNumber\": \"447700900123\", "
            + "\"message\": \"Your verification code is 482913\", "
            + "\"messageType\": \"TEXT\""
            + "}";

        HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.broadnet.me/sms/sendSms"))
            .header("Authorization", "Bearer " + System.getenv("BROADNET_TOKEN"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();

        HttpResponse<String> res = HttpClient.newHttpClient()
            .send(req, HttpResponse.BodyHandlers.ofString());

        System.out.println(res.statusCode() + " " + res.body()); // 200 + message ID
    }
}
```

## How do you send an SMS with Go?

```
package main

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	body := []byte(`{
		"senderId": "BroadNet",
		"destinationNumber": "447700900123",
		"message": "Your verification code is 482913",
		"messageType": "TEXT"
	}`)

	req, err := http.NewRequest(http.MethodPost, "https://api.broadnet.me/sms/sendSms", bytes.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("BROADNET_TOKEN"))
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	id, _ := io.ReadAll(res.Body)
	fmt.Println(res.StatusCode, string(id)) // 200 + message ID
}
```

## How do you send an SMS with C# and .NET?

.NET 6 and later need no NuGet package: HttpClient and System.Net.Http.Json are built in.

```
// .NET 6+ console app (Program.cs) — HttpClient is built in, no NuGet package
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;

using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("BROADNET_TOKEN"));

// PostAsJsonAsync sends Content-Type: application/json
var res = await http.PostAsJsonAsync("https://api.broadnet.me/sms/sendSms", new
{
    senderId = "BroadNet",
    destinationNumber = "447700900123",
    message = "Your verification code is 482913",
    messageType = "TEXT",
});

var id = await res.Content.ReadAsStringAsync();
Console.WriteLine($"{(int)res.StatusCode} {id}"); // 200 + message ID
```

## What comes back, and how do you handle errors?

| Response | Meaning | What to do |
|---|---|---|
| 200 + message ID | Accepted for delivery | Store the ID with your own record; wait for the DLR |
| 400 | Validation error or missing field | Fix the request; do not retry unchanged |
| 401 | Missing or invalid Bearer token | Check the token and the Authorization header |
| 500 | Unexpected server error | Retry with backoff; check the message status before resending |

A 200 means the platform accepted the message, not that the handset received it. Delivery is reported by the delivery receipt; see [what a DLR is](https://www.broadnet.me/answers/what-is-dlr) and [SMS delivery receipts and error codes](https://www.broadnet.me/blog/sms-delivery-receipts-dlr-error-codes). The API has no idempotency header, so keep the returned message ID and check its status before resending, to avoid duplicates. The [error codes](https://www.broadnet.me/developers/error-codes) page lists the rest.

## How do you get it production-ready?

- Keep the token server-side. Never call the SMS API from a browser or mobile app, where the token can be extracted; call your own backend instead.
- Send long messages knowingly: GSM-7 fits 160 characters per SMS, Unicode (UCS-2) 70, and longer texts are split into billed segments. See [the SMS character limit](https://www.broadnet.me/answers/sms-character-limit-explained).
- Queue bulk sends and respect your account's throughput; read [rate limits](https://www.broadnet.me/developers/rate-limits).
- Receive delivery receipts on a [webhook](https://www.broadnet.me/developers/webhooks) and store the final status.
- Validate numbers into international format first; see [E.164 phone number validation](https://www.broadnet.me/blog/e164-phone-number-validation-msisdn).

For very high volume or an existing telecom stack, SMPP may suit better than REST; see [SMPP vs REST](https://www.broadnet.me/compare/sms-api-vs-smpp). BroadNet's platform handles 30,000 SMS per second per node.

## Frequently asked questions

### What is the simplest way to send an SMS from code?

One HTTPS POST to an SMS API with an access token and a JSON body. With BroadNet that is POST https://api.broadnet.me/sms/sendSms with senderId, destinationNumber, message and messageType.

### Is there a BroadNet SDK for Python, PHP or Java?

No. There is one official SDK, @broadnet/cpaas-sdk for TypeScript and Node.js. Other languages call the REST API directly, as shown here, or generate a client from the OpenAPI spec.

### What format should the phone number be in?

International format with the country code and no plus sign or spaces, for example 447700900123.

### Does a 200 response mean the SMS was delivered?

No. It means the message was accepted. The delivery receipt (DLR) reports whether it reached the handset.

### Can I send SMS directly from an Android or iOS app?

Not safely. Put the API call on your server so the access token never ships inside the app, and have the app call your server.

### Where do I find the full API reference?

In the [API reference](https://www.broadnet.me/developers/api-reference) and the [OpenAPI spec](https://www.broadnet.me/developers/openapi).

Code samples are the ones on our developer pages, checked against the published OpenAPI spec. Reviewed 28 September 2026. See our [editorial standards](https://www.broadnet.me/about/editorial-standards).
