i have 1 post 1 get request. I want to send first post request, take id and put on get request. how can i do that with pre-request script
This type of activity is covered in the Postman Learning Centre.
If you are new to Postman, then I would suggest a visit to the Learning Centre.
Overview | Postman Learning Center
Including the Postman Training links under “Resources”.
I would recommend the “Galaxy APIs 101” course first as it gets you used to the application features and GUI.
Then the “Galaxy Testing and Automation” course which teaches you how to assert the responses. It includes defining and using variables from responses and chaining requests.
thank you for response but i can’t find my question’s answer there
The Galaxy Testing and Automation course shows you how to set variables from responses to use in another request.
Store and reuse values using variables | Postman Learning Center
Pretty sure that covers what you’ve asked for.
I guess the point I’m trying to make is that you are unlikely to get much of a response here, unless you have had a go at this yourself first and show what you have already tried.
Not sure what you mean by “do that with a pre-request script”.
You should be able to do this with two requests. The first being your POST request with some code in the tests tab to parse the response and set a collection or environment variable with your ID.
You would then have a GET request which uses that ID. (This is absolutely covered in the training).
If you really want to use a pre-request script, then you can use sendRequest() in your GET request to run the POST request, but its more code and doesn’t sound like its needed based on your scenario.
@michaelderekjones how can i write test, if response url is null send it again. can i do this in posman?
What do you mean by response URL is null.
Can you provide an example response where this happens?
What is the status code for the response?
after 10 sec url will be done. how can i write code wait for url result or wait for 10sec and after that send again
Something like…
const response = pm.response.json();
let requestName = pm.info.requestName;
if (response.url === null) {
setTimeout(function(){}, 10000);
postman.setNextRequest(requestName);
}
i need to send again my get request after 10 sec. my first call
Just change the requestName variable to be the name of the GET call.
let requestName = "requestName";
like this?
const response = pm.response.json();
let requestName = “aksd”;
if (response.url === null) {
setTimeout(function(){}, 10000);
pm.setNextRequest(requestName);
}
Have you tested it? Run it and see.
when i sent post request taken id and put on my get request and called that after 10 sec i get Error: pm.setNextRequest is not a function.
Sorry, I think it might need to be postman.setNextRequest, not pm.setNextRequest.
You also need to run this from within the collection runner as setNextRequest only works with the runner.
thank you @michaelderekjones it’s working and you were
right it should be postman.setNextRequest
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.