Created
July 14, 2020 16:36
-
-
Save smariapena/6db7c013377227f498a43e9033b7caf7 to your computer and use it in GitHub Desktop.
Postman PreRequest Script Example
This file contains 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 appEnv = (pm.environment.name); | |
const userEmail = pm.environment.get('yourloginemail'); | |
const userPass = pm.environment.get('yourloginpassword'); | |
const authBody = { | |
grant_type: "password", | |
email: userEmail, | |
password: userPass, | |
}; | |
const authRequest = { | |
url: `https://{appEnv}/yourauthendpoint`, | |
method: 'POST', | |
header: 'Content-Type: application/json', | |
body: { | |
mode: 'raw', | |
raw: JSON.stringify(authBody) | |
} | |
}; | |
pm.sendRequest(authRequest, (err, response) => { | |
if (!err) { | |
const data = response.json() | |
pm.environment.set('accessToken', data['access_token']); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment