Authentication
To get an access token, use this code:
# Use Basic Auth over HTTPS to get an access token
$ curl -X POST \
--user 'username:password' \
https://whatsapp.turn.io/v1/users/login
> {
"users": [{
"token": "eyJhbGciOHlXVCJ9.eyJ1c2VyIjoNTIzMDE2Nn0.mEoF0COaO00Z1cANo",
"expires_after": "2018-03-01 15:29:26+00:00"
}]
}
Make sure to replace
username:password
with your username and password.
You can get your username and password from the Turn UI > Settings > API & Webhooks. With it you can request an API access token.
This method should be used with caution since generating a new access token will invalidate the previously generated token for this number. If the previous token is actively being used for a service or integration, invalidating it will result in service disruptions or integration failures.
To generate a token without invalidating the previous one, you can use the Turn UI instead of the API endpoint. In the Turn UI > Settings > API & Webhooks, click Create a Token button. This option allows you to generate a new token by specifying its name and expiration date.
Turn expects for the access token to be included in all API requests to the server in a header that looks like the following:
Authorization: Bearer token
You must replace token
with your personal access token.