0

I'm executing a post call which returns a list of headers. One of those headers is called "Bunny-id" and returns a number. (Let's suppose Bunny-id --> 159).

I'm trying to take that number and paste it automatically to my environment..Environment var is already there and it's called "id_pratica_artoo", here's the code:

pm.test("set environment variable for chain", function() {
    var headerData = pm.response.headers;
    pm.environment.set('id_pratica_artoo', headerData.Bunny-id);
});

Executing the POST call with the above test gets me the following error:

set environment variable for chain | ReferenceError: id is not defined

What am I missing?

John Conde
  • 217,595
  • 99
  • 455
  • 496
Andrea
  • 49
  • 8
  • what you are getting in `console.log(headerData)`? – Divyang Desai Mar 21 '19 at 15:20
  • @Div console.log(pm.response.headers) reports an array where the 6th is the information i want. If, for example, i set as follows: `pm.test("test", function() { var bunny_id = pm.response.headers[6]; pm.environment.set('id_pratica_artoo', bunny_id) console.log(pm.response.headers[6]); });` Then, i get "null" on that console.log, as it was impossible to access that information into the array – Andrea Mar 21 '19 at 16:34

1 Answers1

0

resolved by using the following:

pm.test("set environment variable for chain", function () {
pm.response.to.have.header('Bunny-id');
pm.environment.set('id_pratica_artoo', pm.response.headers.get('Bunny-id'));
Andrea
  • 49
  • 8