How to put a parameter from a JSON URL response in a REST Request
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @AAB,
Take a look at the examples here:
I think they will give you some clue.
Tanya Yatskovskaya
SmartBear Community and Education Manager
