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
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
In the tests tab on the GET call you need to set the response to a variable:
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
{{get-response}}
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
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?
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
}
],
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:
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:
{
“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.
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.
What is the error in the console?
Allen
ReferenceError: Content is not defined
Thanks
Allen
[‘Content’]
I should have spotted that My Bad
Thanks
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
You can cast it as a number
const tempId = Number(jsonData[Content]['2020-05-28']['777777'][7]['TempId']);
Then in the POST body, you can remove the quotes around the value:
"TempId": {{test-tempId}}