Skip to content

Instantly share code, notes, and snippets.

@alipandidan
Created December 5, 2019 11:20
Show Gist options
  • Save alipandidan/b9526da09f89da653b71d70a065e1c5c to your computer and use it in GitHub Desktop.
Save alipandidan/b9526da09f89da653b71d70a065e1c5c to your computer and use it in GitHub Desktop.
Get bearer token automatically from API and use it in (Postman as Pre-request scipts)
# Might be useful in Spring boot apps
const postRequest = {
url: 'http://<URL>/auth/login',
method: 'POST',
header: 'Content-Type:application/json',
body: {
mode: 'application/json',
raw: JSON.stringify(
{
"username": <username>,
"password": <password>
})
}
};
pm.sendRequest(postRequest, function (err, res) {
pm.environment.set('accessToken', res.headers.get("X-Access-Token"));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment