Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

If we invoke the Service Callout policy twice in the same API Proxy, it's base path getting appended

If a serviceCallout Policy is called twice in same request it's base path getting appended.

As shown in the attached screenshot, you can notice that

  • The servicecallout.requesturi in the first invocation to Service Callout policy shows it as "/get"
  • However, when the same Service Callout policy is called the second time, the servicecallout.requesturi shows it as "/get/get".

Though the variable servicecallout.Service-Callout-1.target.url shows the value as "http://httpbin.org/get", the request goes as "http://httpbin.org/get/get" and results in a failure "404 Not Found" only for the second request. While the first invocation to Service Callout policy succeeds.

So, wanted to check are we allowed to use the same serviceCallout twice in the same API request?

0 11 1,422
11 REPLIES 11

Hi Amar

Ive been able to reproduce the issue you're experiencing. It appears to be concatenating the servicecallout.requesturi to itself. This does not look like expected behaviour to me, and I will ensure a bug is raised.

With that said, what is your use case that you require multiple requests to the same endpoint?

Hi Amar

Did you manage to get answer to this question. I'm also struggling with the same thing. I have SC policy for logging and I call it to log request and response.

I created two different service callouts but the second concant the before path. Example: the first service callout go to URL http://apigee.com/hello and the second service callout go to URL http://apigee.com/bye. Finally the second service callout is calling http://apigee.com/hello/bye. Why?

Hi Fredwin,

Please use both request variable name different.

eg:

1.

<Request clearPayload="true" variable="myRequest"></Request>

2.

<Request clearPayload="true" variable="myRequest1"></Request>

This should work

Not applicable

You can set the service callout url using assign message policy to a variable and set that as a variable in the service callout. That will not append the base path.

Hi Amar ,

Servicecallout.requesturi flow variable gets duplicated because of the request variable name , as the request variable name is same , path gets appended twice when it called second time.

I would suggest use two different service call out policy and keep request variable name different for both Service callout policies , even though you keep same <path> for both policies.

eg:

1.

<Request clearPayload="true" variable="myRequest"></Request>

2.

<Request clearPayload="true" variable="myRequest1"></Request>

I hope this works for you

I have tried this and it worked for me..

That works but it's not nice having two policies doing exactly the same.. Somehow, variable attribute seems to not support flow/context variables.. Am i wrong?

if by that you mean, something like this "doesn't work"

 

<Request clearPayload="true" variable="{request-variable}"/> <!-- no no no -->

 

... you are correct. The Variable attribute takes a variable name. 

To invoke a single ServiceCallout policy more than once, you would need to  clear the servicecallout.requesturi variable using an AssignMessage, between invocations. Or create 2 different ServiceCallout policies.

Hi there,

yes, that example is perfect to show what i was saying..

i've ended up using two policies because it was more simple and quick than create or changing some js/other policy..

My first attempt was something like this:

 

<Request clearPayload="true" variable="{createUuid()}"/>

 

but i quickly realized that is not intended to work this way :).... but it could .. 🙂

Best,

David.