dimanche 30 septembre 2018

Can Postman Variables be Passed Into Header?

I am trying to string a few Postman requests together for testing.

  1. In the first request I set a global variable as a test script.

    tests['Status code is 200'] = (responseCode.code === 200);
      if (responseCode.code === 200) {
      try {
        let jwt = responseBody.replace(/"/g, '');
        pm.globals.set("jwt", jwt);
        console.log("Variable will be set to", jwt);
      }
      catch(e) {
        console.log(e);
      }
    }
    
    
  2. In the second request I run a pre-request script as

    let jwt = pm.globals.get("jwt");
    
    

Then I try to pass it into the header

enter image description here

Is it possible to pass a value into the header?

When running tests the second request fails due to having an invalid jwt, and the Postman docs only show examples passing variables into the URL.

Aucun commentaire:

Enregistrer un commentaire