Hi , I'm a beginner in Apigee Edge. I need your suggestions to fetch file contents using a ServiceCallout policy.
My requirement is that I need to download a csv file using a ServiceCallout and need to process its content.
My ServiceCallout policy is like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout async="false" continueOnError="false" enabled="true" name="downloadAPI"> <DisplayName>downloadAPI</DisplayName> <Properties/> <Request clearPayload="true" variable="myRequest"> <Set> <Headers> <Header name="Content-Type">application/json</Header> <Header name="Authorization">Bearer {shareFiles.auth_token}</Header> </Headers> <Verb>GET</Verb> </Set> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> </Request> <Response>calloutResponseDownload</Response> <HTTPTargetConnection> <Properties/> <URL>https://{hostName}/{downloadUrl}</URL> </HTTPTargetConnection> </ServiceCallout>
When I try this url in POSTMAN the file is getting downloaded. When I'm trying the same using a ServiceCallout, it is not working.
When I'm print the response (print(context.getVariable("calloutResponseDownload.content"));) it shows as empty.
If I were diagnosing this, I would enable Trace for the API Proxy in question.
You should be able to examine the inputs and outputs of the ServiceCallout.
Some questions for you to explore:
The hostName,downloadUrl and auth_token are set correctly.Got the successful response (status 200) but when I'm print the response it shows as empty
print(context.getVariable("calloutResponseDownload.content"));
is it possible the downloaded content is not a string? Not a printable value? If it's a byte array, it won't print properly.
I'm not sure what I'm looking at with your modified screenshot. the JS getFileContent... I don't know what that is. Maybe that is the thing in which you reference calloutResponseDownload.content .
In the trace, You can highlight a particular step and see exactly what happens for that step. Have you done that?
The SC callout URL looks right to you, but did you actually verify that you got a valid response? I don't see that in anything you've shown me.
Same issue im getting. undefined when extracting context.getVariable("serviceCalloutResponse.content");
old question... .but it may be that the response is chunked or streamed and the full content is not available.
OR you may be referring to an incorrect variable.
It's impossible to say.
Just an additional comment:
"It's not working for me, the variable is undefined" is not enough information for anyone to be able to offer much help to you. Details in your question can help people provide educated guesses as to answers. But please don't ask new questions here, in the comment stream of a 18-month old question. Yes, I know it's similar, but it's also a totally different user, different policy, different problem. Open a new thread please.