Callout Policy Response 200 JSON Payload

Hello Apigee ninjas,

I am trying to get the 200 response JSON payload to display whenever I call a 3rd party service using a proxy endpoint. Is there a way to do this?

I tried to use the assign message policy via "getCustomerResponse" to do this. No luck in getting any response, though. Still getting no response but getting 200 OK respone code.

Would appreciate your help. Thank you!

Please see the following callout policy:

6730-apigee.png

Solved Solved
0 1 456
1 ACCEPTED SOLUTION

Hi

The normal way to use Apigee Edge is as a proxy.

To do this, define a proxy endpoint, and a target endpoint. The proxy endpoint is the inbound, the ingress. It listens for incoming requests. In the proxy endpoint logic flow you can specify conditions under which the proxy will perform various actions. In the simplest case, the proxy endpoint does nothing - it passes through the request it receives to the target endpoint, unchanged. In the "New Proxy" wizard in the Apigee UI, this is called a "pass through" proxy.

The target endpoint is the thing that connects to a backend. There you specify the scheme, hostname, and base path of the target service. In the target endpoint, similar to the proxy endpoint, you again have the option to define logic with Condition elements and so on.

When you configure a proxy endpoint and a target endpoint, the response from the target is automatically placed into the response sent by the proxy to the original client. This page is a more detailed discussion of the concepts I just summarized here.

In the proxy metaphor, a call arrives at Apigee Edge, the optional logic you define runs, and if that logic doesn't end the call, for example by raising a fault , then Apigee Edge invokes the backend. The Apigee Edge proxy receives the backend response , some optional logic runs (transformation? caching?) and then that response is relayed to the client.

You can certainly use a ServiceCallout policy to contact an external system. Generally you do not need that. You would specify the Target to connect to the external system, what I have previously called the "backend". The ServiceCallout policy is intended to augment the basic proxy mechanism, to be called as part of the optional logic before or after invoking the backend.

If you choose to use ServiceCallout in lieu of the backend , then ... you need to manually copy the payload received by the ServiceCallout into the corresponding fields of the "response" object. This probably isn't a good idea, but it's possible. This assignment will work only in the Proxy Response flow, as the "response" object gets reset at the beginning of the response flow. If you assign to response in the proxy REQUEST flow, then those changes get overwritten when the response flow begins.

To assign the fields, you would use the AssignMessage policy. You said you tried the AssignMessage policy , but it didn't work. But, you didn't show us what you tried!

What you want probably looks like this:

<AssignMessage name='AM-CopyServiceCalloutResponseToProxyResponse'>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>getCustomerResponse.content</Name>
    <Ref>response.content</Ref>
  </AssignVariable>
  <AssignVariable>
    <Name>getCustomerResponse.status.code</Name>
    <Ref>response.status.code</Ref>
  </AssignVariable>
</AssignMessage>


To be correct you would want to also copy all the Headers. But that would require a loop, which you cannot do in AssignMessage.

Better to just use the built-in proxy mechanism and avoid all this unnecessary copying.

View solution in original post

1 REPLY 1

Hi

The normal way to use Apigee Edge is as a proxy.

To do this, define a proxy endpoint, and a target endpoint. The proxy endpoint is the inbound, the ingress. It listens for incoming requests. In the proxy endpoint logic flow you can specify conditions under which the proxy will perform various actions. In the simplest case, the proxy endpoint does nothing - it passes through the request it receives to the target endpoint, unchanged. In the "New Proxy" wizard in the Apigee UI, this is called a "pass through" proxy.

The target endpoint is the thing that connects to a backend. There you specify the scheme, hostname, and base path of the target service. In the target endpoint, similar to the proxy endpoint, you again have the option to define logic with Condition elements and so on.

When you configure a proxy endpoint and a target endpoint, the response from the target is automatically placed into the response sent by the proxy to the original client. This page is a more detailed discussion of the concepts I just summarized here.

In the proxy metaphor, a call arrives at Apigee Edge, the optional logic you define runs, and if that logic doesn't end the call, for example by raising a fault , then Apigee Edge invokes the backend. The Apigee Edge proxy receives the backend response , some optional logic runs (transformation? caching?) and then that response is relayed to the client.

You can certainly use a ServiceCallout policy to contact an external system. Generally you do not need that. You would specify the Target to connect to the external system, what I have previously called the "backend". The ServiceCallout policy is intended to augment the basic proxy mechanism, to be called as part of the optional logic before or after invoking the backend.

If you choose to use ServiceCallout in lieu of the backend , then ... you need to manually copy the payload received by the ServiceCallout into the corresponding fields of the "response" object. This probably isn't a good idea, but it's possible. This assignment will work only in the Proxy Response flow, as the "response" object gets reset at the beginning of the response flow. If you assign to response in the proxy REQUEST flow, then those changes get overwritten when the response flow begins.

To assign the fields, you would use the AssignMessage policy. You said you tried the AssignMessage policy , but it didn't work. But, you didn't show us what you tried!

What you want probably looks like this:

<AssignMessage name='AM-CopyServiceCalloutResponseToProxyResponse'>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <AssignVariable>
    <Name>getCustomerResponse.content</Name>
    <Ref>response.content</Ref>
  </AssignVariable>
  <AssignVariable>
    <Name>getCustomerResponse.status.code</Name>
    <Ref>response.status.code</Ref>
  </AssignVariable>
</AssignMessage>


To be correct you would want to also copy all the Headers. But that would require a loop, which you cannot do in AssignMessage.

Better to just use the built-in proxy mechanism and avoid all this unnecessary copying.