Hi,
We have an external API that our Apigee should invoke after some elaboration in our proxy.
I have used a service callout in the request flow :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout async="false" continueOnError="false" enabled="true" name="SC-fileRetrieve"> <DisplayName>SC-fileRetrieve</DisplayName> <Response>versionDataResponse</Response> <Request> <Set> <Verb>GET</Verb> <Headers> <Header name="Authorization">Bearer {accessToken}</Header> </Headers> </Set> </Request> <HTTPTargetConnection> <URL>https://{var_sfdc_url}/{versionData}</URL> </HTTPTargetConnection> </ServiceCallout>And in the response flow I am using an Assign Message to put the Service Callout in the response of the proxy :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="AM-fileTestResponse"> <Set> <Payload contentType="application/octetstream">{versionDataResponse.content}</Payload> </Set> <AssignTo createNew="false" transport="http" type="response"/> </AssignMessage><br><br>
But the file retrieved from the response of my flow is blank.
If i make the same exact request directly to https://{var_sfdc_url}/{versionData} the result is the correct pdf file.
Am I doing something wrong / missing something ?
Answer by Priyadarshi Ajitav Jena · Jan 15 at 11:53 AM
hi,
The service callout response is stored in versionDataResponse and you need to set the response.content to that.
Don't set payload in assign message policy. Just set the response.content to versionDataResponse using assign message or javascript in the response flow
Hi Priyadarshi,
thanks for answering.
I've modified my AssignMessagePolicy to this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="AM-fileTestResponse"> <AssignVariable> <Name>response.content</Name> <Value>versionDataResponse</Value> </AssignVariable> <!-- <Set> <Payload contentType="application/octetstream">{versionDataResponse.content}</Payload> </Set>--> <AssignTo createNew="false" transport="http" type="response"/> </AssignMessage>
but still the pdf resulting is blank and differ from the response of the direct request to the external api made in postman:
File pdf downloaded by my proxy :
File pdf downloaded by the direct request:
It seems that the bytecode of the file is somewhat corrupted or something like that.
Answer by Priyadarshi Ajitav Jena · Jan 15 at 01:25 PM
This will be different. Just try as below.
<AssignVariable>
<Name>response.content</Name>
<Ref>versionDataResponse</Ref>
</AssignVariable>
Try like this. Don't add payload tags.
I've tried to change the assignMessage in post flow as you described but now i'm not receiving a bytecode anymore, instead a reference to the inmemory variable of apigee:
Also the headers are not correct, you can see now the content-type is application/json and not application/octetstream:
are you able to get the response as expected in the "versionDataResponse" variable in trace?
if yes then see the content type is not matching. you need to set the content type same as you are getting the service callout response.