Overview
Call the BroadNet REST API from Python with the requests or httpx libraries. There is no BroadNet Python package: the only official SDK is for TypeScript and Node.js, not Python. If you want a typed Python client, generate one from the OpenAPI spec with openapi-generator; otherwise the plain HTTP calls below are all you need.
Error handling
Errors return an HTTP status code and an ExceptionResponse JSON body (status, error, message, errorCode, requestUri). resp.raise_for_status() turns them into exceptions. Retry only on network errors and 5xx responses, with backoff; once a call has returned a message ID the send was accepted, so don't resubmit it blindly.
Requirements
Any supported Python 3 version. The synchronous example uses requests and the async example uses httpx; install whichever you use.
Examples
Copy, paste, replace the placeholders — these examples call the production API as written.
pip install requests httpximport 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 IDimport asyncio
import os
import httpx
URL = "https://api.broadnet.me/sms/sendSms"
HEADERS = {"Authorization": f"Bearer {os.environ['BROADNET_TOKEN']}"}
async def send(client: httpx.AsyncClient, number: str, text: str) -> str:
resp = await client.post(
URL,
headers=HEADERS,
json={
"senderId": "BroadNet",
"destinationNumber": number,
"message": text,
"messageType": "TEXT",
},
)
resp.raise_for_status()
return resp.text # message ID
async def main() -> None:
recipients = ["447700900123", "447700900124", "447700900125"]
async with httpx.AsyncClient(timeout=10) as client:
ids = await asyncio.gather(
*(send(client, n, "Your code is 482913") for n in recipients)
)
print(ids)
if __name__ == "__main__":
asyncio.run(main())# Optional: generate a typed Python client from the OpenAPI spec
curl -O https://www.broadnet.me/developers/openapi.yaml
npx @openapitools/openapi-generator-cli generate \
-i openapi.yaml -g python -o broadnet-python