Here I'm storing the value of Etag into variable etag, here the values is printed correctly:
Given path '/price/v4/quote/',quoteId,'/products'
And request requestPayload
When method POST
- print 'headers:', karate.prevRequest.headers
Then status 200
And def etag = responseHeaders['ETag']
- print etag [print] ["3"]
Now I'm passing it to the request header of another api:
* header If-Match = etag
Given path '/price/v4/quote/',quoteId,'/accept'
And request requestPayload
When method PUT
* print 'headers:', karate.prevRequest.headers
Then status 200
* print karate.pretty(response)
But I'm getting following error as the value of etag header comes with regex:
Got invalid quoteVersion for quote 'b25f50bc-0479-4390-b4fe-0620fc6c6139'. quoteVersion '[\"3\"]', actualVersion '3'"}
CodePudding user response:
I think you missed that responseHeaders
is a Map
of List
s. Refer the docs: https://github.com/karatelabs/karate#responseheaders
Try this:
And def etag = responseHeaders['ETag'][0]
Also we have a better API for headers in the next versions for anyone else coming across this in the future, please refer: https://github.com/karatelabs/karate/issues/1962