Reputation: 77
I have a scenario where I have to get the value from a hyperlink in the response and assign it to a variable, which I can pass this variable into the url. Here is the json response
{
"activationDate": "2019-08-20T14:39:07.953",
"expirationDate": "2023-01-30T14:39:07.953",
"timestamp": "637078348862871855",
"links": [
{
"href": "https://someurl/api/data/c27f3dc3-dcf6-4958-a559-6bf222d880ce",
"rel": "self"
},
{
"href": "https://someurl/api/data/users/c27f3dc3-dcf6-4958-a559-6bf222d880ce",
"rel": "credentials"
},
{
"href": "https://someurl/api/access/data/c27f3dc3-dcf6-4958-a559-6bf222d880ce",
"rel": "access"
}
],
"firstName": "APITest",
"lastName": "User",
"emailAddress": "[email protected]",
"ada": true,
"isDeleted": false,
"alerts": [
]
}
I need only this value "c27f3dc3-dcf6-4958-a559-6bf222d880ce" from the response which I can pass in the url in another scenario.
Not sure how can I get that value using get keyword in karate
Upvotes: 2
Views: 4224
Reputation: 58058
Do it in 2 steps:
* def temp = response.links[0].href
* def id = temp.substring(temp.lastIndexOf('/') + 1)
Upvotes: 2