To use the PathStack API, you must pass a JWT access token in the header of each request. This is for security to ensure no one else can access your data.

Generating an access token

To get an access token, you need to make a call to the /token endpoint and pass your username and password.

Access tokens expire 60 minutes after they are generated. Once an access token has expired you will no longer be able to use it and any API calls you try to make will return a 401: JWT has expired error response with a message that the token has expired. You will then either have to generate a new token with the /token endpoint, or you can use the Refresh Token from the original /token call to get a new Access Token.

This will return a response that looks something like this:

JSON
{
  "data": {
    "token_type": "Bearer",
    "expires_in": 3600,
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJld2ZlZXdmZmUiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9.TgSl52RmirkU3f1tYG6E5lK5Ptt1C0_KSOSj9H-WYAQ",
    "sub": "a6caf0bd-dbdf-4dfb-bcab-34f73e4c5b64"
  }
}

Now that you have an Access Token, you can begin making requests to the PathStack API.

Using a refresh token

To get a new token, you can either authenticate again with your username and password, or you call the /refresh endpoint. The latter option is often preferable since you will not need to store your username and password for later use.

Using the sub and the refresh_token, you can call the /refresh endpoint to get new access and refresh token.