Skip to content

Instantly share code, notes, and snippets.

@Oleksandr-Moik
Created August 24, 2023 19:59
Show Gist options
  • Save Oleksandr-Moik/8cee98e134f48c464afc0fbfdfd5850a to your computer and use it in GitHub Desktop.
Save Oleksandr-Moik/8cee98e134f48c464afc0fbfdfd5850a to your computer and use it in GitHub Desktop.
Posman utils

set default header for api requests

write in pre-requrest/prepare

pm.request.addHeader('Accept: application/json')

automaticaly set api token to variables

write in tests

const data = pm.response.json();
if(data && data['token']) {
    const token = data['token'];

    pm.environment.set('bearer_token', token)
    pm.collectionVariables.set('bearer_token', token)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment