I am using the Postman Runner and it works pretty smooth when i want to make some calls (patch, post, put) for the same guid in a particular order. But now i would like to make several get calls and use the results in the body of a post call. For example
GET call 1
“value”: “Employee A”
GET call 2
“value”: “Employee A”
Is this possible and if so, how do i do this? I found some articles that hint on using Tests an Pre-request scripts but not with a clear explanation
for a case like this. I did manage to use Tests to fetch data and transfer it to the variables but no easy way to fetch data and transfer it to the body of a Post all.
Hoping for some good advice, very much appreciated.
If you are new to Postman I would recommend the Postman training links which are located under “other resources” in the Learning Centre.
Other resources | Postman Learning Center
The “Galaxy API’s 101” course gets you used to sending requests and the GUI.
The “Galaxy Testing and Automation” gets you used to testing your responses and using variables, basic scripting, etc.
This should cover your scenario.
Also take a look at the following.
Go through the training courses, and if you hit any issues. Post what you’ve got and someone here should then be able to help with your specific request.
Please use the preformatted text option in the editor when pasting code. It’s stops everything from being aligned to the left and keeps the indents and formatting.
The articles have been very helpfull and i am now able to automatically use the data of a get in the body of a post. However i am receiving a “Cannot read properties of undefined (reading ‘0’)” error in case there is no value chosen from the underlying table, so when its null.
The below input in Tests works fine if the GET can return data from the underlying table. But if no choice is made from the underlying table, so when its null, i get the error message.
bodydata = JSON.parse (responseBody) // to parse json response
valuestandardFunction = bodydata._embedded.standardFunction.key
console.log (“value of standardFunction:” + valuestandardFunction)
Somehow i want it to make the choice to get the info if there is any and otherwise use null. I tried with ‘to.be.oneOf’ but somewhere i am doing something wrong. I hope someone can give me some insight in this.
Values can be a string, null, an array, or another object. (It can get complex).
undefined is not the same as null.
undefined means it can’t find the key.
null means it can find the key, but its null.
Although you can probably deal with undefined elements, I recommend that you don’t.
You need to be in control of your test data. It needs to return the same result each and every time and you base your tests on those results.
If you want to test null, then you ensure that you have test data that will illicit that response. (Which means you might have more than one request to the same end point to test out all of these scenarios).
Thanks for the answer. I haven’t been able to fix it yet but i am getting closer. I’ll formulate my question differently in a separate post.