# Get a response on a variable

**URL:** <https://community.postman.com/t/get-a-response-on-a-variable/6888>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [July 31, 2019, 3:09pm UTC](https://community.postman.com/t/get-a-response-on-a-variable/6888 "2019-07-31T15:09:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gabriel](https://community.postman.com/u/gabriel)\
**Post date:** [July 31, 2019, 3:09pm UTC](https://community.postman.com/t/get-a-response-on-a-variable/6888/1 "2019-07-31T15:09:35Z")

</div>

**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**

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/b/b29727428a299c70dd8fc824b71d4a5de0a10ac1.png)

**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/](https://learning.getpostman.com/docs/postman/scripts/test_examples/) if i put text in place of .json it returns the whole body.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 31, 2019, 3:26pm UTC](https://community.postman.com/t/get-a-response-on-a-variable/6888/2 "2019-07-31T15:26:36Z")

</div>

Hey @gabriel.concheto

Welcome to the community 🏆

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. 🙂

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:

> [@Sharing tips and tricks with others in the Postman community](https://community.postman.com/t/sharing-tips-and-tricks-with-others-in-the-postman-community/5123/5):
>
> Extracting values from a JSON response I notice lots of questions from the community which all have a similar flavour - Users are having trouble extracting data from a JSON response body when the value is within an array. These are normally JavaScript related questions, more than specific Postman questions but I want to use this thread to offer more support around this problem. For these examples I’ll be using the [https://randomuser.me](https://randomuser.me) API, this returns lots of random user data, in a JSON form…

\*Post edited to reference the correct value - my bad 😬

---

<div class="post-metadata">

**Author:** ![gabriel](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@gabriel](https://community.postman.com/u/gabriel)\
**Post date:** [July 31, 2019, 4:33pm UTC](https://community.postman.com/t/get-a-response-on-a-variable/6888/3 "2019-07-31T16:33:24Z")

</div>

^^ 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!

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 31, 2019, 5:00pm UTC](https://community.postman.com/t/get-a-response-on-a-variable/6888/4 "2019-07-31T17:00:27Z")

</div>

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