B. Magic
B. Magic

Reputation: 23

Is there a way to use just one REQUEST in Postman, using two APIs?

I currently have one collection in Postman, with two folders. First folder has two POST request.

  1. Send a file to the server and then tests if file has been uploaded successfully with some Pre request script that changes the date and time. Here's a screenshot below:

First Request

  1. Checks if the file on the first request has been uploaded in the server successfully. Using another API to make it work.

Second Request

Now, I wanna combine these both so I don't have to run two requests? Is there any way I can do that on Postman? Any help would be great! :)

Upvotes: 1

Views: 1088

Answers (2)

Danny Dainton
Danny Dainton

Reputation: 25901

Could you make use of the pm.sendRequest() function inside the Tests tab to fire off a request to see if the file has been uploaded?

This is the example snippet you would get in the application:

pm.sendRequest("https://postman-echo.com/get", function (err, response) {
    console.log(response.json());
}); 

Some more usage examples can be found here: https://gist.github.com/madebysid/b57985b0649d3407a7aa9de1bd327990

Upvotes: 1

Evert
Evert

Reputation: 99618

Generally calling an API requires a HTTP request. If you want to make less requests, the service you are using needs to define a special API that does both things at once.

If the service you are using does not have an API specifically for that purpose, then you will need to make 2 requests.

The question I would ask myself is: Why do I care if there are 2 requests instead of 1. And if there's a reason why that's a problem for me, is there another way I can solve that problem.

Upvotes: 0

Related Questions