Create a client
apiKey is the only required option. Creating a client makes no network call.
The SDK reads no environment variable. The key and every setting come from the options object: read ISNAP_API_KEY yourself and pass it, as the sample does.
Client options
The constructor throws a plain
Error, synchronously, when an option is invalid. For apiKey the message is iSnap SDK: apiKey is required when the key is missing or is not a string, and iSnap SDK: apiKey cannot be empty or whitespace when it is empty or contains only whitespace.
The client has no option for default headers, a proxy, logging or an API version. Pass headers with each call. The SDK sends no API version and negotiates none.
Read response headers with fetch
A method resolves with the data of the response: the status and the headers of a successful response are not available to your code. To read them, pass a fetch that wraps the global one. This client logs the rate-limit headers of every response:
Per-call options
Every method takes a last, optional argument with the options of that call:
Three rules apply:
- On the four list iterators (
messages.list,chats.list,webhooks.deliveriesandwebhooks.events) thequeryoption is ignored: only the filters argument is sent. On every other method, an argument of the method overrides the same key inquery. headerscan add headers and can replaceUser-Agent,AcceptandContent-Type. It cannot replaceAuthorization, nor theIdempotency-Keythe SDK sets.- There is no per-call timeout.
timeoutMsis set on the client and applies to each attempt. To stop one call, retries included, pass asignal: see Cancellation.
attachments.upload takes two more options, pollIntervalMs and maxPolls: see The attachments helper.
Headers
A request body is your object passed through
JSON.stringify. Field names are the snake_case names of the API: the SDK converts no name.
Credentials
A client has one credential and sends it with every request. That includes the operations that need no credential:client.version(), client.health(), lines.list(), lines.get(), areaCodes.list(), apps.manifest() and trial.status() also require a client created with a non-empty apiKey.
The SDK takes an API key or a trial key, not a dashboard session. 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. See Test keys.
To call with a trial key, create a second client with that key:
Call an operation that has no method
client.request(method, path, body?, opts?) calls any path of the API. It applies the same authentication, retries, idempotency key and error handling as the typed methods, and resolves with the data of the response. You give the type of that data: the sample below declares the fields it reads.
GET /v1/attention is the operation of the API reference that has no method:
client.request is also how you page through a list by hand.
Console output
When a response carries aDeprecation header, the SDK writes one console.warn per method, path and Sunset value for the life of the process. The warning names the removal date and the successor path when the API sends them. Versioning and compatibility describes these headers.
Apart from that warning, the SDK writes nothing to the console and keeps no log.