Get Imgur auth token
POST https://api.imgur.com/oauth2/token

Imgur access tokens are only valid for 1 month. We could add the access_token value to our environment under a new imgurAccessToken
key, the same way we previously added our Imgur credentials to Qodex, but we'd have to come back in a month and update our key.
Instead, let's automate the authorization process to make sure we always have a valid token.
First, we will use Imgur's OAuth 2.0 process to get a refresh token.
In the Qodex app, under a new request (separate from this example collection), click on the Authorization tab, select OAuth 2.0, click on the Get New Access Token button, and fill in these values:
- Token Name: can be anything
- Auth URL: https://api.imgur.com/oauth2/authorize
- Access Token URL: https://api.imgur.com/oauth2/token
- Client ID: {{imgurClientId}}
- Client Secret: {{imgurClientSecret}}
- Grant Type: Authorization Code
- Request access token locally: checked
Click on Request Token to initiate the OAuth 2.0 flow authorizing the Qodex app to connect to your Imgur account.
Once that is completed, add the refresh_token
value to your environment under the imgurRefreshToken
key, the same way you added your Imgur credentials to Qodex in Step 2.
Now, we can submit a request using our refresh_token
to get a new access_token
.
Method:
POST
URL:
https://api.imgur.com/oauth2/token
Body: Under the Body tab of our second request, add the required parameter values using double curly braces to access our environment variables.
Under the Tests tab, we can write scripts in JavaScript to execute any logic after the request is sent. Looking closer at the Imgur response object, we can parse the JSON object to retrieve and store our data, like a new access token.
Let's set our environment variable based on the response from this request using Qodex’s setEnvironmentVariable()
method and pass in our key and value.
Creating an environment variable allows us to access this stored value in subsequent requests when the entire collection is run with our environment.
Read more about OAuth 2.0 authentication and environment variables in the Qodex docs.
Request Body
[{"name"=>"refresh_token", "value"=>"{{imgurRefreshToken}}", "datatype"=>"string"}, {"name"=>"client_id", "value"=>"{{imgurClientId}}", "datatype"=>"string"}, {"name"=>"client_secret", "value"=>"{{imgurClientSecret}}", "datatype"=>"string"}, {"name"=>"grant_type", "value"=>"refresh_token", "datatype"=>"string"}]