Generate Access Token - Staging
Generates an access token with an API key in the Staging environment.
After you have created an API key in the Portal, consisting of a client ID and client secret, you can generate an access token (JWT) for authorization of Megaport APIs. JWTs are short lived and the expiry time is set when you create the API key in the Portal (between 5 minutes and 24 hours). The expiry can be seen in the response of this endpoint, and is represented in seconds.
Tip: You can use the https://jwt.io/ site to learn more about and verify the access token. Copy the access token (JWT) into the Encoded box, it will display decoded information about the token. For example, in the Payload Data, the iat value indicates when the token was issued (seconds since Unix epoch) and the exp value indicates when the token expires.
The request URL that you need to use depends on the environment in which you are generating an access token. In the Staging environment, this request URL should be used:
For more details on environments, see Environments.
Provide values for these parameters in the Authorization tab of the call:
-
Username– The client ID that you copied when creating the API key. -
Password– The client secret that you copied when creating the API key.
Note: These parameters contain sensitive data. If you are working in a collaborative environment, you might want to set the client ID and client secret as the variables {{apiKeyClientId}} and {{apiKeyClientSecret}} respectively.
In the Body tab, set the Body coding format to x-www-form-urlencoded, and enter a key called grant_type which is set to a value of client_credentials.
Using the access token
After you successfully generate an access token, you will see these values in the response:
-
access_token- The access token (JWT). -
expires_in- The expiry of the token, measured in seconds. For example, if the expiry was set to 24 hours in the API key, this value would be 86400 (seconds). If the expiry was set to 5 minutes, then this value would be 300. -
token_type- Bearer
Copy the access token from the response.
You can create a new variable for the access token, ensuring that you copy the access token into the CURRENT VALUE field of the variable entry. For example, call the new variable {{access_token}}.
For each API call that you need to send, in the Authorization tab, the Type should be set to Bearer Token and the Token should be set to the access token variable {{access_token}}.
Authentication
Basic authentication of the form Basic <base64(username:password)>.
Request
Response
Generate Access Token - Staging / Generate Access Token - Staging / Generate Access Token - Production / Generate Access Token - Production