Consume POST request data to GET and DEL requests



  • I get an id from a POST request and I want to use that id in the GET and DEL requests. I don't want to do it manually; if there is automated way that my read and delete requests consume my POST request data, please let me know. Important note: I'm using Postman currently, so it would be great if someone can let me know how to do it in Postman.



  • This what the Postman variables do,

    Assuming that your response data is:

    {
       name: "something"
       user:{
          id:"12"
       }
    }
    

    in the test script section, add below command

    let jsonData = JSON.parse(responseBody);
    pm.environment.set("id", jsonData.user.id)   //this stores the id to env variable 'id'
    

    now you can access the id value from the next requests like:

    for non-sprit areas like body,header, url etc:

    {{url}}/api/version/{{id}}
    

    For test and pre-request scripts:

    pm.environment.get("id")
    

    enter image description here

    Update Example:

    I have set the variable "pdhide" from create user endpoint's test tab and now calling from pre-requisite tab for update endpoint:

    enter image description here



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 3
  • 2