Sending to many recipients
The API sends one message per request. To message a list, loop over it, and pace the loop to the rate limit.
There is no bulk endpoint
Each call to POST /api/v1/sms/send/ queues exactly one message. A list of 1,000 recipients is 1,000 requests.
Pace your requests
An account can make 120 send requests per minute, so a batch can go out at about 2 messages a second. Send at that pace instead of firing everything at once and handling the 429 responses. When you do get a 429, wait the number of seconds in the Retry-After header. See Rate limits.
Give every message a stable request ID
Use something from your own data, such as campaign-42-recipient-1007. If your job is interrupted and restarts, resending the same IDs within 24 hours won't message anyone twice.
Example
import os, time, requests
API = "https://www.connecfy.com/api/v1/sms/send/"
HEADERS = {"Authorization": f"Bearer {os.environ['CONNECFY_API_KEY']}"}
def send_all(recipients, text, sender):
for i, number in enumerate(recipients):
while True:
r = requests.post(API, headers=HEADERS, timeout=10, json={
"to": number, "from": sender, "message": text,
"request_id": f"campaign-42-{i}",
})
if r.status_code == 429:
time.sleep(int(r.headers.get("Retry-After", "5")))
continue
if r.status_code == 402:
raise RuntimeError("Monthly allowance reached; stop and contact Connecfy")
r.raise_for_status()
break
time.sleep(0.5) # about 2 requests per second, under the 120/minute limitCheck your allowance first
Each message uses one unit of your monthly allowance. Before a large batch, compare the number of recipients with the messages remaining shown under Billing in the dashboard. See Usage and billing.
ConsentOnly message people who have agreed to hear from you, and honour requests to stop. See Content and consent.