Skip to content

Instantly share code, notes, and snippets.

@smariapena
Created July 14, 2020 16:36
Show Gist options
  • Save smariapena/6db7c013377227f498a43e9033b7caf7 to your computer and use it in GitHub Desktop.
Save smariapena/6db7c013377227f498a43e9033b7caf7 to your computer and use it in GitHub Desktop.
Postman PreRequest Script Example
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