How to validate service callout response? If response is success and if there is no error then how to call second API?

Not applicable

I have a scenario – We are creating one proxy which internally call two different end points.

For example Proxy URL like as - <apidev>/security/token

- First call will return auth token

- In second call I am passing auth token

Currently I am doing as this way –For the first call I am calling Service callout and in second call, I am reading token value from Service callout response and passing to second API – this's working fine.

Query – Actually I want to validate response of service callout, if its success and if there is no error then I want to call second API call, please suggest the way.

1 3 1,144
3 REPLIES 3

Not applicable

Hi @Mohammad Farooqui,

Welcome to Apigee community.

Attribute "continueOnError" (default value as "false") of ServiceCallout policy ensures that normal flow will stop and process will move to Error flow.

Edge treats HTTP codes 4XX or 5XX as errors, and HTTP codes 1XX, 2XX, 3XX as success. However, you can use the <HTTPTargetConnection> tag to configure your own set of HTTP codes corresponds to success or error.

For more details refer here.

Cheers,

Rajesh Doda

Thank you Rajesh.

But I want to read JSON response for e.g.

{"status" : "success/error"}

Based on the above response-

If status = "success" then call to next API in the sequence

If status = "error" then terminate flow with api error response

Please suggest.

Not applicable

Sure, following steps would be required in the sequence:

1. ExtractVariables policy to read "status" variable from response payload.

2. Compare "status" variable against "error" as part of the flow step

3. Use "RaiseFault" policy to raise an error if this condition is true.

RaiseFault policy will stop the processing in the normal flow and enter the error flow.

Cheers, Rajesh