Skip to content

Instantly share code, notes, and snippets.

@AliMilani
Last active July 22, 2023 08:41
Show Gist options
  • Save AliMilani/5e7f90664bc8d0b0a46c7cd8f2d60fe0 to your computer and use it in GitHub Desktop.
Save AliMilani/5e7f90664bc8d0b0a46c7cd8f2d60fe0 to your computer and use it in GitHub Desktop.
This Postman test extracts the "authorization" and "x-refresh-token" headers from the response and stores them in environment variables "USER_ACCESS_TOKEN" and "USER_REFRESH_TOKEN" if they exist.
// let data = JSON.parse(responseBody);
var authorization = pm.response.headers.get('authorization')
var refreshToken = pm.response.headers.get('x-refresh-token')
if (!authorization) return
if (authorization) pm.environment.set("USER_ACCESS_TOKEN", authorization?.split(' ')[1]);
if (refreshToken) pm.environment.set("USER_REFRESH_TOKEN", refreshToken);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment