Reputation: 31
I have a chain of requests that walk through a multi-step transaction. I want to generate a value for an orderId and itemId in the first request and reuse the values in each subsequent request.
I've used the Chance extension to generate each of these ids in the first request.
In subsequent requests, I'm using the Request Parsed Body dynamic value and referencing the JSON attribute where each of these ids was created.
Rather than returning the value from the first request, it is generating a new id using the Chance extension.
My APIs require these two values to be consistent across a group of requests. How can I get this to happen correctly?
NOTE: I also tried this with the values defined in an environment thinking that the environment would be evaluated once, but that also results in a different value on each request in the group.
I can create a custom extension to accommodate this but I am not sure how best to approach the problem. Advice would be appreciated.
Upvotes: 2
Views: 85
Reputation: 2408
We've just published 5 new Dynamic Values, that will let you re-use random values sent in headers, URL params, body and request URL. Here is the link: https://luckymarmot.com/paw/extensions/?extension_type=dynamic_value&q=sent
Assuming you have:
The solution is to get the value from the last HTTPExchange of A.
The only way to do this at the moment is through a custom dynamic value (inline JS)
function evaluate(context){
const otherRequest = context.getRequestByName('Request A')
const lastExtrange = otherRequest.getLastExchange()
return JSON.parse(lastExtrange.requestBody).email // to get the body
return lastExtrange.getRequestHeaderByName('X-some-header-from-a')
};
This can be placed in request B were you want the value from A:
For reference of the api see: HTTPExchange
Upvotes: 2