I need help to create api Proxies that join 2 services Zoho Creator and ebay Trading API
Zoho Creator have possibility to send https POST with json but constructor in Zoho doesn’t support multilayer json (only simple pair), eBay trading api accept only https XML
I send simple json request
{“XMLDATA”:”<GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents">...}
i need to convert this into XML request with value of XMLDATA in the body
and change type of Content-type: in the header to “text/xml”
When i post request from Zoho creator, i obtain in apigee
Content-type: application/x-www-form-urlencoded
Content-length: 234
Content:
XMLDATA=%3CGeteBayOfficialTimeRequest+xmlns%3D%22urn%3Aebay%3Aapis%3AeBLBaseComponents%22%3E+%3CRequesterCredentials%3E+%3CeBayAuthToken%3EMyToken%3C%2FeBayAuthToken%3E+%3C%2FRequesterCredentials%3E+%3C%2FGeteBayOfficialTimeRequest%3E
Value of XMLDATA – url encoded.
Can someone help me how to get it work.
On exit i need:
Content-type: text/xml
Content like:
<?xml version="1.0" encoding="utf-8"?><GeteBayOfficialTimeRequest xmlns="urn:ebay:apis:eBLBaseComponents"><RequesterCredentials><eBayAuthToken>
4
Answers
well i get it works. In Zoho Creator
1) ExtractVariables Policy
2) AssignMessage Policy to create new POST
Looks pretty straight forward but let me know if I’m missing anything.
1) ExtractVariables Policy
If your inbound payload looks like this:
Then do a JSON extraction like this:
This will only work if the Content-Type of your request is application/json (if you want to force it, do an AssignMessage policy just before it and
2) AssignMessage Policy to create new POST payload
Now that you have a variable named xmldata you can create a new request message with an AssignMessage policy like this:
Note that you have to escape the < and > in the Payload XML (otherwise Apigee tries to parse it as configuration XML) and note that {xmldata} variable in curlybraces.
Here are the links to the documentation on Apigee if you need more details about the policies:
Extract Variables
http://apigee.com/docs/api-services/content/extract-message-content-using-extractvariables
Assign Message
http://apigee.com/docs/api-services/content/extract-message-content-using-extractvariables
If putting XML inside JSON you need to ensure that the XML is escaped and handle it properly. Otherwise you’ll have invalid JSON. If possible, try submitting the JSON request with the data you need and don’t embed the XML. Then as the previous answer suggested:
ExtractVariables
policy and<JSONPath>
config.AssignMessage
policy.Try out DefiantJS (http://defiantjs.com) which has functions that might help you. Among others, it enables you to search JSON structure with XPath query expressions, transform XML to/from JSON structure.
You can find example of DefiantJS and XPAth examples here:
http://defiantjs.com/#xpath-evaluator
Check out this jsfiddle as example;
http://jsfiddle.net/hbi99/Yc6cc/