Postman doesn't accept using variables in the request body due to pre-request authorization script

Describe the bug
I’d like to use variables in the request body but Postman didn’t accept that due to my pre-request authorization script, so I get 401 Unauthorized error.

Any suggestions how can I fix that are very apreciated.

Request headers:

User-Agent:ApiRequestTask/1.0
Content-Type:application/vnd.api+json
Accept:application/vnd.api+json
Authorization:{{AuthorizationToken}};{{AuthorizationSignature}}

Request body:

{
  "data": {
    "type": "password_request",
    "attributes": {
      "email_address": "{{user.email}}"
    }
  }
}

Athorization pre-request script:

var secret = pm.environment.get("AuthorizationSecret");

var body = '';
var hash = '';

if(request.method == 'GET') {
    hash = CryptoJS.HmacSHA256('', secret).toString(CryptoJS.digest);
} else {
    hash = CryptoJS.HmacSHA256(request.data, secret).toString(CryptoJS.digest);
}

postman.setEnvironmentVariable("AuthorizationSignature", hash);

Screenshots


App information:

  • App Type: Native App
  • Postman Version: 6.1.4
  • OS: macOS High Sierra 10.13.5

@Konstantin.V It appears that you’re trying to access nested properties (api.stage and user.email), which is not currently supported. You’ll have to store the URL and email values as distinct variables, and then access them with the usual {{...}} syntax.

Hey @kunagpal,
yes, of course my URL and email values are stored as variables, this is not the source of my issue.

The problem was related to my pre-request authorization script and this solution helped me to resolve it:

var data = request.data.replace('{{user.email}}', 
postman.getEnvironmentVariable("user.email"));