Ask a Question

How to put a parameter from a JSON URL response in a REST Request

SOLVED
AAB
Regular Contributor

How to put a parameter from a JSON URL response in a REST Request

Hello,

 

For my project I need to read a JSON response through a URL. I've managed to do so, but now I should put a particular property into the REST Request. How can I do this please?

So far:

//cfr.  https://www.leveluplunch.com/groovy/examples/get-webpage-content-url-uri/
//https://community.smartbear.com/t5/SoapUI-Pro/How-to-Parse-a-JSON-Response-Using-Groovy-Examples/td-p/155770
import groovy.json.JsonSlurper

def getConceptSchemes = "https://LinkToMyEnvironment".toURL().getText()
//parse json string using JsonSlurper - basically converts it to a groovy list
def parsedJson = new groovy.json.JsonSlurper().parseText(getConceptSchemes)
//get data
def findAGC = parsedJson.find { it.name == 'ACTIVITY_GROUP' }
log.info "result for specific beID: " + findAGC

This gives me the answer from the Json response.

This is a first step in my TestCase.

The second step is a REST Request with parameter 'beId' that I need to fetch from the response.

Response:

{"beId":"d4f897d05508caa12d77d732ffbc652f821c0a16c2f457277c2565f0b890f62e","name":"ACTIVITY_GROUP","reportingAuthority":"KBO","links":[{"rel":"self","href":"http://LinktomyEnvironment/d4f897d05508caa12d77d732ffbc652f821c0a16c2f457277c2565f0b890f62e{?lang}"}]},

How can I do so please?

 

Thanks in advance

AAB

2 REPLIES 2
HimanshuTayal
Community Hero

@AAB 

 

The response which contains beID is a JSON then you can again use JSONSLURPER if not then you can write some logic like use split or replace then split, so that you will be able to get the desired id.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
cancel
Showing results for 
Search instead for 
Did you mean: