What?
This is an article documenting how to send a Zoho Deluge Map request to an API which is expecting nested/2d/multi-dimensonal arrays. In the example below, we are posting to a PHP script for testing but I have since sent something similar to an API expecting nested arrays (not sure if they were PHP) and it works.
Why?
This took me several days and in the end only going through various forums and documentation, I found a solution which worked for me. Note that usually I could customize the receiving PHP script to receive a JSON request and process it that way but my usage was to send data to a Third-Party API over which I had no control.
What I need to send to the 3rd-party API:copyrawstyler
{
"auth": {
"secret": "can_you_keep_a_secret",
"key": "aaabbbbccccddddeeeeffff11112222"
},
"data": {
"member_id": "123456",
"channel_name": "shopify",
"item_name": "Joel's Awesome Life",
"item_price": "priceless"
}
}
- {
- "auth": {
- "secret": "can_you_keep_a_secret",
- "key": "aaabbbbccccddddeeeeffff11112222"
- },
- "data": {
- "member_id": "123456",
- "channel_name": "shopify",
- "item_name": "Joel's Awesome Life",
- "item_price": "priceless"
- }
- }
What Zoho sends to the 3rd-party API:
Sending a map request using the
invokeUrl() function, the odd thing is that Zoho's request adds double-quotes to the request and escapes the other double-quotes sending something like this:
copyrawstyler
{
"auth": "{\"secret\": \"can_you_keep_a_secret\",\"key\":\"aaabbbbccccddddeeeeffff11112222\"}",
"data": "{\"member_id\": \"123456\",\"channel_name\": \"shopify\",\"item_name\": \"Joel's Awesome Life\",\"item_price\": \"priceless\"}"
}
- {
- "auth": "{\"secret\": \"can_you_keep_a_secret\",\"key\":\"aaabbbbccccddddeeeeffff11112222\"}",
- "data": "{\"member_id\": \"123456\",\"channel_name\": \"shopify\",\"item_name\": \"Joel's Awesome Life\",\"item_price\": \"priceless\"}"
- }
What I have in Delugecopyrawstyler
m_Auth = Map();
m_AuthSub = Map();
m_AuthSub.put("secret","can_you_keep_a_secret");
m_AuthSub.put("key","aaabbbbccccddddeeeeffff11112222");
m_Auth.put("auth",m_AuthSub);
m_Data = Map();
m_DataRecord = Map();
m_DataRecord.put("member_id","123456");
m_DataRecord.put("channel_name","shopify");
m_DataRecord.put("item_name","Joel's Awesome Life");
m_DataRecord.put("item_price","priceless");
m_Data.put("data", m_DataRecord);
- m_Auth = Map();
- m_AuthSub = Map();
- m_AuthSub.put("secret","can_you_keep_a_secret");
- m_AuthSub.put("key","aaabbbbccccddddeeeeffff11112222");
- m_Auth.put("auth",m_AuthSub);
- m_Data = Map();
- m_DataRecord = Map();
- m_DataRecord.put("member_id","123456");
- m_DataRecord.put("channel_name","shopify");
- m_DataRecord.put("item_name","Joel's Awesome Life");
- m_DataRecord.put("item_price","priceless");
- m_Data.put("data", m_DataRecord);
How?
So this is more of an annoyance then an impossible task... because it is possible, the technique above is simply wrong. The trick and solution is a lot simpler than you might think...
Category: Zoho :: Article: 740