Refresh Token after Authentication.
If your access_token has expired, we’ll guide you on how to use your refresh_token to get back on track.
If you successfully authenticated to the Newsletter2Go API you should have received a bearer token, which must be included in all API calls. If you don’t know how to get these credentials, please check out the help article “Authenticating to the API”.
This is what your credentials should look like:
{ "access_token": "<your_access_token>", "expires_in": 7200, "token_type": "bearer", "scope": null, "refresh_token": "<your_refresh_token>", "account_id": "awtfn5jn", "type": "user" }
The attribute access_token is the actual bearer token that should be used in the header of all subsequent requests. Always placed after the word Bearer.
{ "Authorization": "Bearer <your_access_token>" }
Your access_token will expire after 2 hours (7200 seconds) and will no longer be suitable to perform calls to our API. In order to get a new access_token, you need to run the OAuth Refresh Access Token endpoint.
Let’s build the token refresh POST request.
The request is made of two parts, headers and body.
Headers
For the headers, you must set two variables, Content-Type and Authorization.
Content-Type defines the kind of data that will be exchanged in the request. For the Newsletter2Go API, you should always set this variable to application/json.
Authorization is the variable that will carry the Base64 encoded authentication key. Make sure to use the word Basic before your Base64 encoded key.
Check out this help article if you don’t know how to encode your authentication key to Base64.
For this example, your headers should look like this :
{ "Content-Type": "application/json", "Authorization": "Basic <auth_key_base64>" }
Body
For the body, you will need to set 2 variables: refresh_token and grant_type.
The refresh_token is the token you got in the response to your authentication.
You should always set the variable grant_type to https://nl2go.com/jwt
For this example, the body should look like this :
{ "refresh_token": "<your_refresh_token>", "grant_type": "https://nl2go.com/jwt" }
Execute the POST request. Here is how the HTTP request should look like for this example:
POST /oauth/v2/token HTTP/1.1 Host: api.newsletter2go.com Content-Type: application/json Authorization: Basic <auth_key_base64> { "refresh_token": "<your_refresh_token>", "grant_type": "https://nl2go.com/jwt" }
You’ll get a response from the server.
{ "access_token": “<your_new_access_token>”, "expires_in": 7200, "token_type": "bearer", "scope": null, "refresh_token": “<your_refresh_token>“, "account_id": "awtfn5jn", "type": "user" }
You can now use your new access_token to create subsequent requests to our API.
When implementing this into your application , keep in mind the refresh_token is valid for 1 month.