how do I extract variables from a service callout to assign them to the response?

Not applicable

I want to callout a service, extract the variables from that service's json and assign those variables to the response of this flow. The service callout's response contains the variables, but I am unable to extract them. What can I do to fix this?

Policies and final response below

service callout policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="refresh-external-callout">
    <DisplayName>refresh external callout</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <QueryParams>
                <QueryParam name="grant_type">refresh_token</QueryParam>
                <QueryParam name="refresh_token">{oauthv2accesstoken.generate-external-token.refresh_token}</QueryParam>
            </QueryParams>
            <FormParams>
                <FormParam name="client_id">{request.formparam.client_id}</FormParam>
                <FormParam name="client_secret">{request.formparam.client_secret}</FormParam>
            </FormParams>
            <Verb>POST</Verb>
        </Set>
    </Request>
    <Response>calloutResponse</Response>
    <LocalTargetConnection>
        <Path>/am/oauth2/token</Path>
    </LocalTargetConnection>
</ServiceCallout>

extract variables policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="extract-refresh-callout-response">
    <DisplayName>extract refresh callout response</DisplayName>
    <Properties/>
    <JSONPayload>
        <Variable name="access_token">
            <JSONPath>$.access_token</JSONPath>
        </Variable>
        <Variable name="refresh_token">
            <JSONPath>$.refresh_token</JSONPath>
        </Variable>
        <Variable name="expires_in">
            <JSONPath>$.expires_in</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">calloutResponse</Source>
</ExtractVariables>

assign message policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="external-token-response">
    <DisplayName>external token response</DisplayName>
    <Properties/>
    <Set>
        <Payload contentType="application/json" variablePrefix="@" variableSuffix="#">
            {
                "access_token": "@access_token#",
                "expires_in": "@expires_in#",
                "refresh_token": "@refresh_token#"
            }
        </Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="https" type="response"/>
</AssignMessage>

response I get:

{
    "access_token": "",
    "expires_in": "",
    "refresh_token": ""
}
2 3 6,204
3 REPLIES 3

Make sure the response from the service callout includes the content-type: application/json header, or the extract variables will not be able to parse it as json.

Also, just in case, double check the spelling of the field names and location within the payload.

If you post a curl directly to the token service with the response headers and full payload we can better help too.

sjm2000
Participant V

Sorry to reply to old post, however, its working for me

You should be able to access the variable like this {access_token} since you seem to correctly extract the value from the json payload.

In trace you should be able make sure if access_token is populated or not.