Forum Discussion

sgardner's avatar
sgardner
New Contributor
8 years ago

How do I transfer newly created unique id's for a successful POST to the next test step

Hey everyone,

 

I am working on a REST API that can be used to construct a set of data. The data is set up in a hierarchy that is linked through a set of unique identifiers (id's). For instance, I create an initial test step (1) which submits a POST request for Resource A; If successful, the POST request will return with an unique identifier for Resource A, This unique identifier is then needed to submit a POST request to Resource B, test step (2). The problem is that the identifier generated for test step 1 on Resource A is unique and I can not figure out how to capture and transfer that id to the next test step without manual intervention. Does anyone know of a way to transfer a returned value from a POST test step to the next test step? 

3 Replies

    • sgardner's avatar
      sgardner
      New Contributor

      I'm not quite sure how to use this for my needs though. I understand what the transfer property tool can be used for but do not know how to use it for my needs. The API POST I am doing only creates a response that can be viewed in JSON and RAW, however, the RAW response does not have the unique ID that was just created in the response. How would I be able to grab this ID field from the JSON response and transfer it to my next test step?

      • PaulMS's avatar
        PaulMS
        Super Contributor

        Can you copy an example of the JSON response and next test step request?

         

        The example from the article above uses XPath for XML content type, but in the Property Transfer test step you should change the path language to JSONPath.

         

        The property can then be used in a JSON request in the same way as the XML example

        e.g. ${#TestCase#SessionID}

         

        Now when executed, the SessionID is transfered to the specified TestCase property and can later on be used in any request via standard property-expansion (or another property-transfer), for example in a logout request we could have

        <logout>
        <sessionID>${#TestCase#SessionID}</sessionID>
        </logout>

        Which would replace the expansion with the saved SessionID when the request is being sent.