cancel
Showing results for 
Search instead for 
Did you mean: 

Transfer property to aplication/x-www-urlencoded request

SOLVED
mihai_lita
New Contributor

Transfer property to aplication/x-www-urlencoded request

Hi,

 

I've created a test suite which contains a test case.

1. I am calling an API that returns in it's response a clientId. eg. /api/v1/getClients

2. I am retrieving that clientId and use it to call another API, e.g /api/v1/client/{clientId}

3. The API from point 2 is returning accountNumber

4. I am trying to call another API (eg. api/v1/client/getAccount ) where I need to pass the accountNumber in the payload of the request, but the payload needs to be in application/x-www-form-urlencoded format : accountNumber=abc123&currency=USD&country=US

I am failing in transfering the retrieved accountNumber into the payload. 

Any ideas?


Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
mihai_lita
New Contributor

Re: Transfer property to aplication/x-www-urlencoded request

I managed to get it working with the following solution

JSON RESPONSE FROM WHERE I NEED DATA

{

"clientId" : "1234556",

"accountNumber" : "abc123"

}

Groovy script I used:

 

def response = new groovy.json.JsonSlurper().parseText(context.response)

log.info "clientId is: ${response.clientId}"
log.info "accountNumber is: ${response.accountNumber}"

context.testCase.setPropertyValue('CLIENT_ID', response.clientId.toString())
context.testCase.setPropertyValue('ACCOUNT_NUMBER',  response.accountNumber.toString())

And the in the post request I did the following

Content-Type : application/x-www-form-urlencoded

Body: 

clientid=${#TestCase#CLIENT_ID}&accnt_number=${#TestCase#ACCOUNT_NUMBER}

 

Thank you!

 

View solution in original post

2 REPLIES 2
nmrao
Community Hero

Re: Transfer property to aplication/x-www-urlencoded request

A screen shot possible with error?


Regards,
Rao.
mihai_lita
New Contributor

Re: Transfer property to aplication/x-www-urlencoded request

I managed to get it working with the following solution

JSON RESPONSE FROM WHERE I NEED DATA

{

"clientId" : "1234556",

"accountNumber" : "abc123"

}

Groovy script I used:

 

def response = new groovy.json.JsonSlurper().parseText(context.response)

log.info "clientId is: ${response.clientId}"
log.info "accountNumber is: ${response.accountNumber}"

context.testCase.setPropertyValue('CLIENT_ID', response.clientId.toString())
context.testCase.setPropertyValue('ACCOUNT_NUMBER',  response.accountNumber.toString())

And the in the post request I did the following

Content-Type : application/x-www-form-urlencoded

Body: 

clientid=${#TestCase#CLIENT_ID}&accnt_number=${#TestCase#ACCOUNT_NUMBER}

 

Thank you!

 

View solution in original post

New Here?
Join us and watch the welcome video:
Top Kudoed Authors