Cancelling a scheduled SMS through the API, for example when the customer has already paid

WhatsApp & APIs·· 68 views· 3 min read

The short answer: send POST /v1/sms/messages/{id}/cancel with the id of the scheduled SMS, before its time comes. Only your own account's messages that are still scheduled can be cancelled. If the credits had already been taken, they go back to the balance.

The usual case: the customer paid before the reminder

1 The invoice is created in your system, due on the 20th.
2 Your system schedules the reminder for three days before, with send_at, and stores the returned id with the invoice.
3 The customer pays on the 15th. When the payment is recorded, your system calls cancel with that id.
4 The reminder never goes out, so the customer does not get "your invoice is due" after paying.

The same goes for a rebooked appointment, a delivery that changed day or postponed maintenance: cancel the old notice and schedule a new one. How to schedule: scheduling notices through the API.

The possible answers

Answer What it means
Success The SMS is cancelled. credits_returned says how many credits came back; since a scheduled message is usually only charged when it goes out, this is often zero.
409 with not_cancellable Too late: the message already went out, is going out, or was cancelled before.
404 There is no message with that id in this account.
Do not leave cancelling to the last minute. When the time comes the message enters sending and can no longer be cancelled. Cancel as soon as the reason for the notice goes away.

Retrying safely

Send the Idempotency-Key header on the cancel request too: if the connection drops and your system repeats it, you get the same answer. With a sandbox_ key the API checks everything and changes nothing, which is handy for testing the flow.

To confirm the result, look up GET /v1/sms/messages/{id}: the status says whether it was cancelled, and charged says whether credits were ever taken.

Want notices that call themselves off when they are no longer needed? See the API page.

See the API page

SEE ALSO

Scheduling SMS notices through the API: send_at, time zones and when credits are charged

Payment reminder SMS: when to send it, what to write and ready-to-use examples

Expiry and renewal notices by SMS: contracts, licences and insurance before they lapse

SMS API errors and message statuses: what each one means and what to do

Sending SMS through the API: key, permissions, Sandbox and your first request

SMS notices from your own WHMCS: a hook that calls our SMS API on invoices and payments

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from R118.80/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.