Using imgur public API to try some Postman's features including:
- Environment and Collections Variables
- Pre-requests and Tests scripts
- Dynamic Variables
- Oauth2 Authentication and refreshing its tokens when expired automatically using pre-request scripts
- Fancy reports using HTMLEXTRA
- Node.js >= v10
- Newman:
npm install -g newman
- HTMLExtra:
npm install -g newman-reporter-htmlextra
Download or Clone the project. Once you cd to the project folder:
newman run "imgur.postman_collection.json" -e "Imgur - PRD.postman_environment.json" --iteration-count 1 --reporters cli,htmlextra
where:
--iteration-count
: is the number of iterations (repetitions)--reporters
: the test execution outputs- cli: the prompt/terminal
- html: default newman's html report generator
- htmlextra: a fancy report template
baseUrl
: https://api.imgur.comversion
: api version, initially equals to 3clientId
andclientSecret
: obtained when you subscribe your app at imgur serviceaccessToken
andrefreshToken
: used to store its respectives values when we get it
expiresIn
: To control the Token ExpirationtokenTimestamp
: Set the Time of the Token creationprefixList
: List of preffixes that can be used when creating a albumnewAlbumHashes
: Got after the execution of the POST request to record the Album Id after its creationrandomAlbumName
: Dynamically obtained using a sample fromprefixList
, a fixed string" album "
and a Dynamic Variable from postman (neat!)
In this solution, I'll need to get manually the first pair of access and refresh token. After that, I'll refresh automatically when access token expires.
Right clicking at the collection, go to Edit at the context menu, and then to the Authentication tab.
Select Oauth 2.0
as the type of authentication. After that, click on Get New Access Token
to setup all info, then Request Token
:
Callback URL: https://www.getpostman.com/oauth2/callback
Auth URL: https://api.imgur.com/oauth2/authorize
Access Token URL: https://api.imgur.com/oauth2/authorize
At this moment, you're going to be requested to loggin to imgur and if everythig is ok, you're going to get a Token ready to be used.
Note: all requests that need to authenticate, could use
Inherit auth from parent
at its Auth tab. Although, for our purpose, choose theBearer Token
option, and fill the Token field with the Enviroment variable{{accseeToken}}
. This way, every time we change the variable value, the token will be changed in every request.
Note 2: Either choosing
Inherit auth from parent
orBearer Token
anAuthorization
entry will be added to request Header automatically.
After configuring and getting correctly the first pair of tokens, copy and paste its values to its respectives environment variables.
Try to run some simple request to see if your basic setup is functioning
To be continued...