Usage
To get started using wait tokens, you need to first create a token using thewait.createToken
function:
wait.forToken
function:
wait.completeToken
function:
url
it returns. This is an HTTP callback:
wait.createToken
Create a waitpoint token.options
ThecreateToken
function accepts an object with the following properties:
The maximum amount of time to wait for the token to be completed. Defaults to “10m”.
An idempotency key for the token. If provided, the token will be completed with the same payload
if the same idempotency key is used again.
The time to live for the idempotency key. Defaults to “1h”.
Tags to attach to the token. Tags can be used to filter waitpoints in the dashboard.
returns
ThecreateToken
function returns a token object with the following properties:
The ID of the token. Starts with
waitpoint_
.The URL of the token. This is the URL you can make a POST request to in order to complete the token.The JSON body of the POST request will be used as the output of the token. If there’s no body the output will be an empty object
{}
.Whether the token is cached. Will return true if the token was created with an idempotency key and
the same idempotency key was used again.
A Public Access Token that can be used to complete the token from a client-side application (or
another backend). See our Realtime docs for more details.
Example
wait.completeToken
Complete a waitpoint token.parameters
The ID of the token to complete.
The data to complete the token with.
returns
ThecompleteToken
function returns an object with the following properties:
Whether the token was completed successfully.
Example
From another language
You can complete a token using a raw HTTP request or from another language.wait.forToken
Wait for a token to be completed.parameters
The token to wait for.
returns
TheforToken
function returns a result object with the following properties:
Whether the token was completed successfully.
If
ok
is true
, this will be the output of the token.If
ok
is false
, this will be the error that occurred. The only error that can occur is a
timeout error.unwrap()
We provide a handy.unwrap()
method that will throw an error if the result is not ok. This means your happy path is a lot cleaner.
Example
wait.listTokens
List all tokens for an environment.parameters
ThelistTokens
function accepts an object with the following properties:
Statuses to filter by. Can be one or more of:
WAITING
, COMPLETED
, TIMED_OUT
.The idempotency key to filter by.
Tags to filter by.
The period to filter by. Can be one of:
1h
, 1d
, 7d
, 30d
.The start date to filter by.
The end date to filter by.
returns
ThelistTokens
function returns a list of tokens that can be iterated over using a for-await-of loop.
Each token is an object with the following properties:
The ID of the token.
The URL of the token. This is the URL you can make a POST request to in order to complete the token.The JSON body of the POST request will be used as the output of the token. If there’s no body the output will be an empty object
{}
.The status of the token.
The date and time the token was completed.
The date and time the token will timeout.
The idempotency key of the token.
The date and time the idempotency key will expire.
The tags of the token.
The date and time the token was created.
The output of the token is not included in the list. To get the output, you need to retrieve the
token using the
wait.retrieveToken
function.Example
wait.retrieveToken
Retrieve a token by ID.parameters
The ID of the token to retrieve.
returns
TheretrieveToken
function returns a token object with the following properties:
The ID of the token.
The URL of the token. This is the URL you can make a POST request to in order to complete the token.The JSON body of the POST request will be used as the output of the token. If there’s no body the output will be an empty object
{}
.The status of the token.
The date and time the token was completed.
The date and time the token will timeout.
The idempotency key of the token.
The date and time the idempotency key will expire.
The tags of the token.
The date and time the token was created.
The output of the token.
The error that occurred.