Get a response on a variable

Describe the bug
value is not being assigned to variable(he create the variable but dont assigned the value).

Expected behavior
I need to get the report_id on a variable.

Screenshots

App information:

  • App Type Windows
  • Postman Version [7.3.4]

Additional context
I tried this examples and yt postman videos https://learning.getpostman.com/docs/postman/scripts/test_examples/ if i put text in place of .json it returns the whole body.

Hey @gabriel.concheto

Welcome to the community :trophy:

It looks like the response body is an array that contains objects. You would need to reference which object you want to get the information from or it won’t know where to look. :slight_smile:

As the property you need is in the second object, you need to reference that by specifying the index location. It’s zero indexed so the second one would be [1].

From your example code, you could do this to get that value:

response[1].report_id

You can find more information about accessing JSON from a response body here:

*Post edited to reference the correct value - my bad :grimacing:

1 Like

^^ thanks, i tried to use:
response[0].report_id

but the value was not assigned to variable, i used:
response[1].report_id

and it worked.

Thanks for your help!

1 Like

Ha - You’re right, I rushed out an answer and it should have been 1. :pensive:

1 Like