servicecall out policy failing with 500 error when the same url is working when provided in target backend

Not applicable

Hi ,

I'm using service call out policy to do a HTTPS call in the proxy pre flow. But it is failing with HTTP status code 500. When I use the same url in target backend I'm able to connect it successfully without any issue. Can you please let me know if I'm missing out anything here.

Below is my service call out policy details.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout name="ServiceCallOut_request" enabled="true" continueOnError="false" async="true">
    <DisplayName>3servicecallout</DisplayName>
    <Properties/>
    <Request variable="JSONcontent" clearPayload="true">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <Verb>POST</Verb>
            <Payload>{request.content}</Payload>
        </Set>
    </Request>
    <Response>MatchServiceCallResponse</Response>
    <HTTPTargetConnection>
        <URL>https://backend.url</URL>
      </HTTPTargetConnection>
</ServiceCallout>

Before the service call out , I have assign message policy . Below is the assign message policy code.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="AssignMessage_request" enabled="true" continueOnError="false" async="false">
    <DisplayName>AssignMessage_request</DisplayName>
    <AssignTo type="request" transport="http" createNew="false"/>
    <Copy source="request">
        <Payload contentType="application/json" variableSuffix="#" variablePrefix="%">%requestJSONcontent#</Payload>
    </Copy>
    <Set>
        <Path>/pathname</Path>
    </Set>
    <AssignVariable>
        <Name>target.copy.pathsuffix</Name>
        <Value>false</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>
0 7 357
7 REPLIES 7

hi @seetharaman S.S

Is backend.url a variable set somewhere in the flow ? If it is, please pass it as {backend.url}. Also please check your trace to see if correct request, URL are set while executing service callout policy.

Hi ,

Backend url is a hardcoded value. In the trace I'm able to see proper value coming in "ServiceCallout.requesturl".

@seetharaman S.S - I dont see anything wrong then. Can you confirm if you are getting a response from the service callout ? Does this proxy have a target end point as well and if yes, if that correctly configured ? If that not correct, you might be seeing a 500 for that.

yes. The proxy has target end point and I'm able to get successful response back from the target. The issue is with the service callout policy and it is failing with 500 status code.

@seetharaman S.S - Can you share the bundle ?

@seetharaman S.S

Couple of things, first your AssignMessage <Copy><Payload> usage is incorrect, should be a boolean. Use <Set><Payload> to set contents of requestJSONcontent. See http://docs.apigee.com/api-services/reference/assign-message-policy#copyelement-copypayloadelement.

Second, <Set><Path> doesnt work in AssignMesasge See http://docs.apigee.com/api-services/reference/assign-message-policy#setelement-setpathelement

Third, you should be able to do all this without using the AssgnMessage, just the ServiceCallout, assuming requestJSONcontent is set correctly.

<ServiceCallout name="ServiceCallOut_request" enabled="true" continueOnError="false" async="true">
    <DisplayName>3servicecallout</DisplayName>
    <Properties/>
    <Request clearPayload="false">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <Verb>POST</Verb>
	    <Path>/pathname</Path>
            <Payload contentType="application/json" variableSuffix="#" variablePrefix="%">%requestJSONcontent#</Payload>
        </Set>
    </Request>
    <Response>MatchServiceCallResponse</Response>
    <HTTPTargetConnection>
        <URL>https://backend.url</URL>
      </HTTPTargetConnection>
</ServiceCallout> 

Hi,

Where you able to find the issue because I am also facing the same issue.

While hitting the target url it is working but the servicecallout is giving 500 error