3

Can anyone let me know how to set and get the 'request.data' into a global variable as I am intended to access the request body of a post request in a subsequent get request later?

I tried the below, but this is not working.

pm.globals.set("reqBody", JSON.parse(request.data));

pm.expect(response.name).to.equal(pm.globals.get(reqBody.pr_practice_name))
Avai
  • 41
  • 3
  • 3
    "is not working" is a useless problem description. What is the result, exactly? Are you getting any errors? –  Oct 10 '19 at 12:55
  • I get the below error: "ReferenceError: reqBody is not defined" – Avai Oct 10 '19 at 13:36
  • I understand reqBody is of type object, So I can understand that I am missing something in the get() method above in order to access the object properties. Could you let me know how to get this? – Avai Oct 10 '19 at 13:41
  • 2
    My guess is you need `pm.globals.get("reqBody").pr_practice_name` –  Oct 10 '19 at 14:19

1 Answers1

1

As Chris G replied above, the following resolved my issue:

pm.globals.get("reqBody").pr_practice_name
Avai
  • 41
  • 3