Hi,
I've an API that requires enhancement/enrichment from an intermediate service.
Here's what I'm doing
Step 1: Read input request & Extract required values from request body to call intermediate service and Clear input request
Step 2: Form request to call intermediate service
Step 3: Extract results from intermediate service response
Step 4: Enhance/Enrich input request with extracted results in step 3
How do I retrieve input request in step 4 and enrich the payload for calling end target.
This is a classic Mashup service proxy.
Step 1 - Use Extract Variable Policy to extract the required values from request body and also to cleat the request payload.
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1"> <DisplayName>Extract Variables 1</DisplayName> <Source clearPayload="true">request</Source> <!-- clears the payload specified in Source after extracting data from it.--> <VariablePrefix>Matthew</VariablePrefix> <IgnoreUnresolvedVariables>true|false</IgnoreUnresolvedVariables> <JSONPayload> <Variable name="name"> <JSONPath>$.abc</JSONPath> </Variable> </JSONPayload> </ExtractVariables>
Step 2 - We could use Javascript/Assign Message to form a request payload and then use it in a Service callout policy. For simplicity use a Service Callout policy to form the request and call intermediate service.
<ServiceCallout name="ServiceCallout-GeocodingRequest1"> <DisplayName>Inline request message</DisplayName> <Request variable="intermediateRequest"> <Set> <Payload contentType="application/json"> { "some-variable":{Mathew.name} } </Payload> </Set> </Request> <Response>intermediateResponse</Response> <HTTPTargetConnection> <URL>http://intermediate-service.com</URL> </HTTPTargetConnection> </ServiceCallout>
Step 3 - Use Extract Variable policy (we can use Assign Message policy with Template also) to extract variables from the intermediate Service callout response.
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-2"> <DisplayName>Extract Variables 2</DisplayName> <Source clearPayload="false">intermediateResponse</Source> <VariablePrefix>Matthew</VariablePrefix> <IgnoreUnresolvedVariables>true|false</IgnoreUnresolvedVariables> <JSONPayload> <Variable name="xyz"> <JSONPath>$.xyz</JSONPath> </Variable> </JSONPayload> </ExtractVariables>
Step 4 - As mentioned earlier we could use Javascript/Assign Message to form a request payload before hitting the TargetEndpoint.
If Message Templates is enabled in your org, then we can use Assign Message policy to Extract the JSON payloads and Assign/Create new payloads in a single policy.
@Siddharth Barahalikar Thanks for your reply, I was able to do first 3 steps but I'm actually struck with 4th step. How do I retrieve the input request in step 4 when I've cleared it in step 1.
If you want to use the original request payload, then do not clear in Step 1 use false for clearPayload.
The original payload can be accessed using "request.content" flowvariable.