POST then verifying with a GET

I’ve got a POST that generates some values & successfully sends to an API. I want to run a subsequent GET using the “ID” value in the response body of the POST, but I haven’t had any luck with variables (environment or global, neither seem to work). The specific error I’m seeing is:

There was an error in evaluating the Pre-request Script: ReferenceError: responseBody is not defined

My pre-request script is:

var jsonData = JSON.parse(responseBody);
postman.setGlobalVariable(“id”, jsonData.id);

Not sure what I need to add to get this working, the above is taken right from a very old postman blog post (http://blog.getpostman.com/2014/01/27/extracting-data-from-responses-and-chaining-requests/).

Does anyone have any examples of this in general? POSTing then verifying with a GET?

Thanks

@dleenhouts

Are you running the POST in the pre-request script and then the GET? If you’re doing a POST and then a GET the “var jsonData = JSON.parse(responseBody); postman.setGlobalVariable(“id”, jsonData.id);” in the Tests.

Mick

They’re separate requests. The POST triggers a bunch of services, & I want to run a subsequent GET to verify that those services did what they were supposed to do. And there’s nothing in the response of the POST that I can use to verify that, which is why I want to do a separate GET request that uses the ID returned in the POST response body.

1 Like