How to read text/plain response of ServiceCallout?

I'm trying to make a call from Apigee to target server for token. However for token, it is response is a type of text/plain. Token call is a ServiceCallout policy.

How can I read this with ExtractVariables policy? or I need to try with some other policy here?

I can see "ServiceCallout.response" with generated token with trace, but not able to pass that to target server from header.

0 7 398
7 REPLIES 7

Maybe try a regex within a js callout?

Show an example response payload, and we may be able to provide a more specific hint.

Added postman screenshot for better understanding.

9191-postman-eywgfneftx.png

WIth Service callout, I am able to get token in ServiceCallout.response. But not able to read with extract variable policy, no error but variable is empty while Target Endpoint call.

I tried with Javascript policy with below code:

var token = context.getVariable("ServiceCallout.response");

print("token", token);

Now I am able to get token but partial. Length is 505 where as actual token is of around 1220 in length.

Reading a plain text payload from within JS works for me.

(Imagine a screenshot here showing you the trace UI . For some reason I Cannot upload it)

I cannot imagine why you're seeing only 505 characters instead of the actual 1220.

Attached please find a working API proxy that demonstrates how to read the data.

apiproxy-1k-text-payload-example.zip

Getting error while deployment: "The revision is deployed, but traffic cannot flow. Unknown string function : createUuid"

Ya, that's a function tat is available in Apigee Saas (cloud). It sounds like you are running in OPDK. No problem though - I used that function only to create contrived data for the token payload. I Wanted to make it so that the generated token would be above 1200 characters, as in yoru case.

You can change the AssignMessage policy to just not use those things, and insert arbitrary other data, even static data.

I'm guessing you can figure out how to make that change. If not you can ask here.