Skip to main content
This script sends one message from one of your lines and prints the id and the status of the message. Use it as the starting point of your own send path. Sending messages explains the request and what happens to a message after the API accepts it.
The script acts on your real account. It sends a real message to the recipient you give, and the message counts against the sending limits of the line. An isnap_test_ account key is not a separate test environment: it acts on the same account, lines and billing as an isnap_live_ key.

The script

send-message.ts

Run it

Install the SDK, and typescript and @types/node as development dependencies. Set "type": "module" in the package.json of the project, then save the script as send-message.ts with the tsconfig.json of the overview, and set ISNAP_API_KEY in the environment. The arguments are the id of one of your lines, the phone number of the recipient, and the text.
The line id and the phone number above are placeholders: replace them with yours.

What it prints

A call that resolves means the API accepted the message. It does not mean the message was sent. A first call prints one of two results: A retry with the same key prints the status the message has now, which can be any message status. To follow the message after the send, read it with client.messages.get(id). Held messages explains the holds.

Errors it handles

Errors and retries describes the classes, and POST /v1/messages lists the codes of the operation.

Retry with the same key

The script passes its own idempotencyKey, so that you can retry after an unknown outcome. Run it again with the same line, the same recipient, the same text, and the key it printed as a fourth argument. The API then returns the message already created, in its current state, and sends no second message. With the same key and a different text, the call throws ConflictError with code idempotency_conflict. Send retries one after the other. Idempotency says how long a key stays valid.

Personal data

The recipient and the text are personal data. The script prints the message id and the status only. Do not copy a handle or a message text into logs, tickets or other tools, and refer to a contact by an id of your own.