Unexpected 404 response from ServiceCallout

Not applicable

Hi,

I am using service callout to make a different request based on the first response recevied from backend.

Before Service callout I have used AssignMessage to set up a request payload. In request payload I have set payload with another service whou can fetch the user details.

<Set>
  <Payload contentType="application/json"
     variablePrefix='%' variableSuffix='#'>{
  "url":"https://graph.windows.net/abc.onmicrosoft.com/directoryObjects/{%objectId#}" }
  </Payload>
</Set>

I can see that the object Id is been fetched from the backend in trace. But when the same request is set for service callout it is not fetched or recoginsed and it is throwing 404 resource not found error.

{
    "odata.error": {
        "code": "Request_ResourceNotFound",
        "message": {
            "lang": "en",
            "value": "Resource '{1234aas22d4-20i3-b5a1-jwiew39i3030}' does not exist or one of its queried reference-property objects are not present."
        }
    }
}

Seems the issue is at n/w delay to get the response from backend.

Is there a way to introduce delay at ServiceCallout to wait for the response from backend??

Or I can use time delay function in JavaScript.

If anyone of you have faced this kind of Issue or scenario please help me with code.

Help will be appreciated. Thanks in advance.

0 3 943
3 REPLIES 3

Hi @sumiya

A network delay will cause the request to timeout and show a 502 Bad Gateway error and definitely not 404. Looking at the error message it seems the service was invoked but the object id is not valid, hence 404. Did you check the service callout in trace ? Was the object id set properly in the path ? If it was then should be visible in trace

Hi Snehal,

I could see that the Object Id is correclty fetched and assigned in the assignmessage varaible in the trace.Please fidn the same below.

AssignMessage Trace:

{ "url":"https://graph.windows.net/abc.onmicrosoft.com/directoryObjects/{48h99e4c-ea9a-420d-8ca8-12345678dfg}" }

Error from postman.

{ "fault": { "faultstring": "Execution of ServiceCallout Service-Callout-5 failed. Reason: ResponseCode 404 is treated as error", "detail": { "errorcode": "steps.servicecallout.ExecutionFailed" } } }

Backend throughs 404 error and service callout is treating it as 500 internal server error.

To await for the response from backend I would like to introduce a delay..

This is an old question, but I thought I'd answer anyway, in case it helps someone else.

I'm certain that the conclusion you reached is not correct. You wrote:

Seems the issue is at n/w delay to get the response from backend.

That's not what happened.

The error message you provided gives the key clue. It shows

"Resource '{1234aas22d4-20i3-b5a1-jwiew39i3030}' does not exist or one of its queried reference-property objects are not present."

What are those curly braces doing there? I suppose a resource in the graph is identified by an id which maybe looks like a GUID or UUID. But GUIDs do not have curly braces.

Look at your AssignMessage. You used

<Set>
  <Payload contentType="application/json"
     variablePrefix='%' variableSuffix='#'>{
  "url":"https://graph.windows.net/abc.onmicrosoft.com/directoryObjects/{%objectId#}"
}
</Payload>
</Set>

I see curly braces AND the variablePrefix and variableSuffix wrapping the reference object ID. That's probably not what you want. The resulting payload for that message template will be:

{
  "url":"https://graph.windows.net/abc.onmicrosoft.com/directoryObjects/{1234aas22d4-20i3-b5a1-jwiew39i3030}"
}

You want something like this:

<Set>
  <Payload contentType="application/json">{
  "url":"https://graph.windows.net/abc.onmicrosoft.com/directoryObjects/{objectId}"
}
</Payload>
</Set>

The difference here: I didn't specify explicitly a variablePrefix or variableSuffix. That means the message template will implicitly use the curly braces to denote variable references. So I removed % and # from the string. The result will be

{
  "url":"https://graph.windows.net/abc.onmicrosoft.com/directoryObjects/1234aas22d4-20i3-b5a1-jwiew39i3030"
}

Side note:

the variablePrefix and variableSuffix are not needed, generally. Unless you're sure you need them, don't use them. Just use the default curly braces to refer to variables.

Last thing:

If you really want your API Proxy to delay for "a bit", there IS a way to introduce a delay in an API Proxy. You cannot do it reliably with JavaScript. You can do it with Java. See this callout. Also: you do not need a delay to solve the problem reported in your original message.