# How do you declare the response from a get call into the Payload body of a post call

**URL:** <https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958>\
**Category:** Help Hub\
**Created:** [May 28, 2020, 10:56am UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958 "2020-05-28T10:56:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [May 28, 2020, 10:56am UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/1 "2020-05-28T10:56:54Z")

</div>

Complete Newbie to Postman

So far for tempid i have “tempId”: {{Request#Response#$

Request is the name of the preceding get call

Thanks in advance

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [May 28, 2020, 12:00pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/2 "2020-05-28T12:00:02Z")

</div>

In the tests tab on the GET call you need to set the response to a variable:

```auto
pm.collectionVariables.set('get-response', pm.response.text());

```

Then in the body of your POST, you can just pass in the variable you set from the GET

```auto
{{get-response}}

```

---

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [May 28, 2020, 12:09pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/3 "2020-05-28T12:09:20Z")

</div>

Thanks

So would that be

{  
“Code”: 102563141503,  
“TempId”: {{get-response#$[‘Content’][‘2020-05-28’][‘77777’][7][‘TempId’]},

```
"DiaryDate": "${{get-response#$['Content']['2020-05-28']['77777'][7]['AppointmentDate']}}",
"Bay": 77777,
"ResevationLength": 1,
"Reference": "ABCDE-1234567"

```

}  
Again Many Thanks

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [May 28, 2020, 12:20pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/4 "2020-05-28T12:20:40Z")

</div>

Do you want to use just a piece of the GET response for the POST or do you want to use the entire payload one for one?

---

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [May 28, 2020, 12:31pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/5 "2020-05-28T12:31:31Z")

</div>

Hi

I need to use the entire payload the sructure of the json response from the Get call is:

{  
“Content”: {  
“2020-05-28”: {  
“555555”: [  
{  
“BranchCode”: 666666666,  
“Type”: “dsesds”,  
“Date”: “2020-05-28T08:30:00”,  
“Time”: “08:30”,  
“DiyDate”: “28 May 2020”,  
“Time”: 1,  
“A”: 0,  
“Bay”: 44444444,  
“StatusId”: 128,  
“Status”: “Unavailable”,  
“IsUpdating”: false,  
“ReasonCode”: 90,  
“ReasonDescription”: “STAT UNAVAILABLE”,  
“TempId”: 1483356,  
“SlotId”: null,  
“EntryComment”: null,  
“Booking”: null  
}  
],  
“77777”: [  
{  
“BranchCode”: 102563141503,  
“Type”: “dsesds”,  
“Date”: “2020-05-28T08:30:00”, //I Need this  
“Time”: “08:30”,  
“DiyDate”: “28 May 2020”,  
“Time”: 1,  
“A”: 0,  
“Bay”: 44444444,  
“StatusId”: 128,  
“Status”: “Unavailable”,  
“IsUpdating”: false,  
“ReasonCode”: 90,  
“ReasonDescription”: “STAT UNAVAILABLE”,  
“TempId”: 454554454, // I need this  
“SlotId”: null,  
“EntryComment”: null,  
“Booking”: null  
}  
],

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [May 28, 2020, 12:59pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/6 "2020-05-28T12:59:19Z")

</div>

Ok so you only need two fields. This makes it easier.

In the `tests` tab of your GET request you can add the following exactly how it is written:

```auto
const jsonData = pm.response.json();
const date = jsonData[Content]['2020-05-28']['777777'][7]['Date'];
const tempId = jsonData[Content]['2020-05-28']['777777'][7]['TempId'];

pm.environment.set('test-date', date);
pm.environment.set('test-tempId', tempId);

```

Then in your POST request, you can access these variables with the following:

```json
{
  “Code”: 102563141503,
  “TempId”: "{{test-tempId}}",
  "DiaryDate": "{{test-date}}",
  "Bay": 77777,
  "ResevationLength": 1,
  "Reference": "ABCDE-1234567"
}

```

Keep in mind that given the path you used in your example, this will always be taking the values from the 7th item in the `777777` array in the GET response. If you need to iterate over the values in there, the code would change a little bit.

---

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [May 28, 2020, 1:30pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/7 "2020-05-28T13:30:41Z")

</div>

qallen

Apologies but when i send the request the tests tab does not like the code in the tab, any ideas.

again many thanks for your help.

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [May 28, 2020, 1:42pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/8 "2020-05-28T13:42:33Z")

</div>

What is the error in the console?

---

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [May 28, 2020, 1:53pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/9 "2020-05-28T13:53:33Z")

</div>

Allen

ReferenceError: Content is not defined

Thanks

---

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [May 28, 2020, 2:01pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/10 "2020-05-28T14:01:30Z")

</div>

Allen

[‘Content’]

I should have spotted that My Bad

Thanks

---

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [May 28, 2020, 2:11pm UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/11 "2020-05-28T14:11:31Z")

</div>

Allen

The test passes but the variables dont seem to hold data, if i hver over it i get const tempId: any.

TempId has to be passed an int not as a string

any ideas.

Thanks

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [August 4, 2020, 11:39am UTC](https://community.postman.com/t/how-do-you-declare-the-response-from-a-get-call-into-the-payload-body-of-a-post-call/12958/12 "2020-08-04T11:39:11Z")

</div>

You can cast it as a number

```auto
const tempId = Number(jsonData[Content]['2020-05-28']['777777'][7]['TempId']);

```

Then in the POST body, you can remove the quotes around the value:

```auto
"TempId": {{test-tempId}}

```
