1

I have a GET request to OKTA to retrieve some information that uses some variables etc. It returns a body. I have a second request of type PUT where I manually paste the BODY and make a change to one variable. I am trying to determine if I can remove the manual process of pasting in the response body from the 1st GET request onto the second PUT request.

As an example, I have a URL:

GET https://{{myurl}}/api/v1/apps/{{instanceid}}

This returns some dyanmic JSON data in the payload like so

"blah":{ some more blah
},

"signOn": {
        "defaultRelayState": null,
        "ssoAcsUrlOverride": ""
        "audienceOverride": null,
        "recipientOverride": null
    }

what I am hoping to do is:

PUT  https://{{myurl}}/api/v1/apps/{{instanceid}}
       {replay entire body from 1st request with the modification of

      "ssoAcsUrlOverride": "{{some var that points to a new url}},

}

I have looked at some articles that show:

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
jeyyu2003
  • 47
  • 2
  • 7

1 Answers1

1

First of all, let's validate the JSON response first. Here is the valid JSON with some dummy data.

{
    "blah": "some more blah",
    "signOn": {
        "defaultRelayState": "1",
        "ssoAcsUrlOverride": "www.google.com",
        "audienceOverride": "true",
        "recipientOverride": "yes"
    }
}

1) Save first request's response into a environment variable req_body as follows,

var jsonData = pm.response.json();

pm.environment.set("req_body",  jsonData);

2) In the PUT request, take another environment variable replace_this_body in body.

enter image description here

3) Get the value of E'variable req_body we had set in the first request in Pre-request script. Then change the value of it and set current request's body variable.

var requestBody = pm.environment.get("req_body");

requestBody.signOn.ssoAcsUrlOverride = "https://www.getpostman.com";

pm.environment.set("replace_this_body", JSON.stringify(requestBody));

Finally, you will get updated request data into PUT request!

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
  • Fantastic. I finally had a chance to test it and works great. – jeyyu2003 Sep 13 '19 at 12:17
  • Glad to know that!@jeyyu2003 Please accept this an answer don't forgot to upvote the answer if it helped you. Also read [how this answer would help others](https://meta.stackexchange.com/a/5235) – Divyang Desai Sep 13 '19 at 13:51