Access Token

Generate token with NodeJS

In this article, we will explain how you can generate a Sonetel access token with NodeJS and how you can use it to interact with our API.

To get started, ensure that you have a free Sonetel account. You will have to use your username and password to acquire an access token.

Once that is done get the sample code from GitHub.

The code is a NodeJS module that exports a function called createAccessToken. This function can be used to generate an OAuth access token for a Sonetel account, using the Sonetel API.

The createAccessToken function accepts two arguments:

  1. username: The email address used to sign in at
  2. password: The login password for the Sonetel account.

The function first checks that the username and password arguments are provided. It then constructs an HTTP request to the Sonetel API, using the POST method, the grant_type, username, and password parameters, and basic authentication with the sonetel-api username and password. The request is sent and the response is handled asynchronously, extracting the access token and resolving it as a Promise.

You can find the full API-documentation here.


Photo by Kelly Sikkema on Unsplash