[ServiceCallout] Using the ServiceCallout twice in sequence appends the path

Hello everyone,

I'm having an issue using 2 ServiceCallouts in sequence. They're appending the path, so the request returns an error.

I've tried this solution, but the error keeps the same.

I've tried to put other policies between the SCs, but appears they're being ignored.

I've tried to put one SC on request and another on response. Same error.

I've tried to extract then to SharedFlows, same.

Is there any solution to use multiple SCs in sequence?

#HelpMeDino

0 2 150
2 REPLIES 2

Can you show me your configuration for both of the service callout policies?

I've tried this solution,

Are you therefore using

  1. This "clearPayload" approach?
    <Request clearPayload="true" variable="requestVar">
    
  2. Or, are you using a distinct, explicitly named request variable for each callout?

which one?

I prefer and recommend the latter.

I am not sure if the SC documentation makes it clear, but this is what it does: it creates or uses a Message object. If you don't name one explicitly, then servicecallout will use a default name for its request object. I think what happens is, if you use two SC policies in a row, and you don't specify the name for the request object (as with the variable= in the above code snip), then both SC policies will use the same variable for the request object.

I am unsure about the effect of clearPayload='true' . I beleive that option, when present, will tell SC to clear the payload. I do not know if it will clear the path also.

I cannot think of a good reason to NOT create a new request for each servicecallout policy. Just do it. In SC policy #1:

<Request variable="sc-request-1">...

In SC policy #2:

<Request variable="sc-request-2">...

Thanks for the support, Dino. We're using this:

<Request clearPayload="true" variable="requestVar">

as you can see here:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="SC-get-session">
    <Request clearPayload="true" variable="sc-request-1">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <Headers>
                <Header name="Authorization">Basic {encodeBase64(basic-auth-var)}</Header>
            </Headers>
            <Verb>GET</Verb>
        </Set>
    </Request>
    <Response>sc-response-1</Response>
    <Timeout>5000</Timeout>
    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="ts-1"/>
        </LoadBalancer>
        <Path>/mypath</Path>
    </HTTPTargetConnection>
</ServiceCallout>

And the second one:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="SC-validate-session">
    <Request clearPayload="true" variable="sc-request-2">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <Headers>
                <Header name="Authorization">Basic {encodeBase64(basic-auth-var)}</Header>
            </Headers>
            <Verb>GET</Verb>
        </Set>
    </Request>
    <Response>sc-response-2</Response>
    <Timeout>5000</Timeout>
    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="ts-2"/>
        </LoadBalancer>
        <Path>/mypath-2</Path>
    </HTTPTargetConnection>
</ServiceCallout>