Forum Discussion

bfourie's avatar
bfourie
Occasional Contributor
10 years ago

Dynamic Post Data on POST or PUT (REST)

Hi guys,

Lets assume the following scenario. 

I've created a test with 3 steps.

Step 1: GET -> GetUser. This give me a JSON response with a bunch of fields such as userid, email, name etc.

Step 2: Transfer properties. The only property that makes sense is the whole response.

Step 3: POST -> SetUserActive.

 

I now need to generate some JSON based on the response that was transfered, and add it to the header for the next request. I cannot seem to find a way to do that.

So I set the MediaType to "application/json"

The text below that curently gets the reposnse from my initial request, but I need to alter it, and create a new json strong based on some of the values. Now I can use xpath in the transfer properties section to get specific values, but still still does not explain how I can create a custom json string just below the post header.

I am using the free version for now. I've submitted a request for the company to get the pro version but this is hampered by redtape...

 

{
   "responseCode": "1",
   "responseDescription": "Fully Registered User",
   "userBiographicalInformation":    {
      "firstName": "Joe",
      "lastName": "Bloggs",
      "contactnumber": "0111234567",
      "Id": "1234567890123",
      "emailAddress": "someone@somewhere.com"
   }
}

 

Then for the query on the POST message it should be:

 

{
    "accountId": "123456",
    "userType": "Fully Registered User",
    "Id": "0123456789012"
    "firstName": "Fred",
    "lastName": "Bloggs",
    "contactnumber": "0821234567",
    "emailAddress": "fred@bloggs.com",
    "marketingYN": "N",
}

 

In other words I can extract most of the information from the request response. For Testing the rest of the data will be hardcoded.

 

So I was hoping forsomething like looks like this:

 

{
    "accountId": "123456",
    "userType": {properties.userType},
    "Id": {properties.Id}
    "firstName": {properties.firstName},
    "lastName": {properties.lastName},
    "contactnumber": {properties.contactNumber},
    "emailAddress": {properties.emailAddress},
    "marketingYN": "N",
}

2 Replies

  • scottkib's avatar
    scottkib
    Occasional Contributor

    I'm assuming that you have both methods created in your resource.

     

    If you have the variables declared in your TestCase properties, you should be able to  to paste the following in the request of the PUT/POST step with media type 'application/json'

     

    It wont run individually, but when executing the test case, it should pull the parameters in from the transfer.  Asssuming that your transfer step is saving as userType, Id, etc and that those are declared in the TestCase.

     

    {
        "accountId": "123456",
        "userType": "${#TestCase#.userType}",
        "Id": "${#TestCase#.Id}",
        "firstName": "${#TestCase#.firstName}",
        "lastName": "${#TestCase#.lastName}",
        "contactnumber": "${#TestCase#.contactNumber}",
        "emailAddress": "${#TestCase#.emailAddress}",
        "marketingYN": "N",
    }
    • bfourie's avatar
      bfourie
      Occasional Contributor

      Thanks! Just gave this a try, and works like a charm. I just have 2 steps in the middle. I created a properties object, and moved all the values in there 1st, then read them from tcPropperties. so rather than #TC1 I'm reading them from something like this:

      "lastName": "${tcProperties#lastName}",