Created
May 20, 2022 16:03
-
-
Save mahammedzkhan/a29fd0f67847d39abff1c249543ca46d to your computer and use it in GitHub Desktop.
Pre-request script for authentication in Postman requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const username = pm.environment.get("authUser"); | |
const password = pm.environment.get("authPass") | |
const options = { | |
url: 'https://api.be/v1/auth/token', | |
method: 'POST', | |
header: { | |
'Authorization': 'Basic ' + btoa(username + ':' + password) | |
} | |
}; | |
pm.sendRequest(options, function (err, response) { | |
const responseJson = response.json(); | |
if (responseJson.access_token) { | |
pm.environment.set("authToken", responseJson.access_token); | |
pm.globals.set("authToken", responseJson.access_token); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment