For Zoho Services only:


I'm actually part of a bigger team at Ascent Business Solutions where we have support technicians and project consultants. Support is for smaller technical fixes but this can include developments, reports or integrations; depending on the size of the task. Projects are for more time-consuming developments such as revamps of the Zoho Suite of apps or on-site training. The advantage of a team is that if I am out-of-office for a day or so, there is always someone at Ascent Business Solutions who can deal with any queries/issues you may have.

Our support rates can be found and purchased at http://ascentbusiness.co.uk/zoho-support-2. A support bundle doesn't have an expiry date. So whether we can do what you want within the bundle and a year later need further support, if there are minutes left on the bundle then there is no additional charge.

Our project rates for bigger developments can be found at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices and will involve a dedicated project consultant along with developers who will hold your hand through the development process.

If you want help building a solution for one of the Zoho Apps in the Zoho Suite, contact us on 0121 293 8140 (UK) or by email at info@ascentbusiness.co.uk. You can also visit our website at http://ascentbusiness.co.uk.

I regularly build and specialize in 2-way API integrations for Xero, Shopify and eBay.

Zoho Deluge: Post a multi-dimensional or nested array to a 3rd-party API

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:
copyraw
{
  "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"
  }
}
  1.  { 
  2.    "auth": { 
  3.      "secret": "can_you_keep_a_secret", 
  4.      "key": "aaabbbbccccddddeeeeffff11112222" 
  5.    }, 
  6.    "data": { 
  7.      "member_id": "123456", 
  8.      "channel_name": "shopify", 
  9.      "item_name": "Joel's Awesome Life", 
  10.      "item_price": "priceless" 
  11.    } 
  12.  } 
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:
copyraw
{
  "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\"}"
}
  1.  { 
  2.    "auth": "{\"secret\": \"can_you_keep_a_secret\",\"key\":\"aaabbbbccccddddeeeeffff11112222\"}", 
  3.    "data": "{\"member_id\": \"123456\",\"channel_name\": \"shopify\",\"item_name\": \"Joel's Awesome Life\",\"item_price\": \"priceless\"}" 
  4.  } 
What I have in Deluge
copyraw
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);
  1.  m_Auth = Map()
  2.  m_AuthSub = Map()
  3.  m_AuthSub.put("secret","can_you_keep_a_secret")
  4.  m_AuthSub.put("key","aaabbbbccccddddeeeeffff11112222")
  5.  m_Auth.put("auth",m_AuthSub)
  6.  m_Data = Map()
  7.  m_DataRecord = Map()
  8.  m_DataRecord.put("member_id","123456")
  9.  m_DataRecord.put("channel_name","shopify")
  10.  m_DataRecord.put("item_name","Joel's Awesome Life")
  11.  m_DataRecord.put("item_price","priceless")
  12.  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... Doing the above, I would get a really messy response (I'm targeting an API made with ExpressionEngine) such as:

Fatal error: Uncaught Error: Class '\Webservice\Service\Exception' not found in /home/thirdpartyapi/public_html/thirdpartyapi_controlpanel/user/addons/thirdpartyapi_webservice/Service/Format.php:86 Stack trace: #0 /home/thirdpartyapiorg/public_html/thirdpartyapi_controlpanel/user/addons/thirdpartyapi_webservice/Service/Format.php(66): thirdpartyapi\Webservice\Service\Format->__construct('auth[key]=06cda...', 'php') #1 /home/thirdpartyapiorg/public_html/thirdpartyapi_controlpanel/user/addons/thirdpartyapi_webservice/libraries/services/webservice_rest.php(206): thirdpartyapi\Webservice\Service\Format->factory('auth[key]=06cda...', 'php') #2 /home/thirdpartyapiorg/public_html/thirdpartyapi_controlpanel/user/addons/thirdpartyapi_webservice/libraries/services/webservice_rest.php(149): Webservice_rest->call_method('create_entry') #3 /home/thirdpartyapiorg/public_html/thirdpartyapi_controlpanel/user/addons/thirdpartyapi_webservice/Core/Hook/SessionsStart.php(106): Webservice_rest->__construct() #4 /home/thirdpartyapiorg/public_html/thirdpartyapi_controlpanel/user/addons/thirdpartyapi_webservice/ext.thirdpartyapi_webservice.php(8 in /home/thirdpartyapiorg/public_html/thirdpartyapi_controlpanel/user/addons/thirdpartyapi_webservice/Service/Format.php on line 86
Rather than assuming Zoho Deluge maps and lists are JSON variables, let's send a strange hack instead:
copyraw
m_NestedRequest = Map();
m_NestedRequest.put("auth[key]",v_AuthKey);
m_NestedRequest.put("auth[secret]",v_AuthSecret);
m_NestedRequest.put("data[member_id]","123456");
m_NestedRequest.put("data[channel_name]","shopify");
m_NestedRequest.put("data[item_name]","Joel's Awesome Life");
m_NestedRequest.put("data[item_price]","priceless");
r_PostResponse = invokeurl
[
    url :"https://api.joellipman.com/my_test_api.php"
    type :POST
    parameters:m_NestedRequest
];
  1.  m_NestedRequest = Map()
  2.  m_NestedRequest.put("auth[key]",v_AuthKey)
  3.  m_NestedRequest.put("auth[secret]",v_AuthSecret)
  4.  m_NestedRequest.put("data[member_id]","123456")
  5.  m_NestedRequest.put("data[channel_name]","shopify")
  6.  m_NestedRequest.put("data[item_name]","Joel's Awesome Life")
  7.  m_NestedRequest.put("data[item_price]","priceless")
  8.  r_PostResponse = invokeUrl 
  9.  [ 
  10.      url :"https://api.joellipman.com/my_test_api.php" 
  11.      type :POST 
  12.      parameters:m_NestedRequest 
  13.  ]

The receiving PHP script did however understand this hack as:
copyraw
$v_Key = "aaabbbbccccddddeeeeffff11112222";
$v_Secret = "can_you_keep_a_secret";
$v_PostedKey = "-";
$v_PostedSecret = "-";
if(isset($_POST['auth']))
{
    if(isset($_POST['auth']['key']))
    {
        $v_PostedKey = $_POST['auth']['key'];
    }
    if(isset($_POST['auth']['secret']))
    {
        $v_PostedSecret = $_POST['auth']['secret'];
    }
    if($v_PostedKey == $v_Key && $v_PostedSecret == $v_Secret)
    {
        mail("This email address is being protected from spambots. You need JavaScript enabled to view it.","Post to AscentCloud","Successful Auth");
    }
}
// yields: Successful Auth
  1.  $v_Key = "aaabbbbccccddddeeeeffff11112222"
  2.  $v_Secret = "can_you_keep_a_secret"
  3.  $v_PostedKey = "-"
  4.  $v_PostedSecret = "-"
  5.  if(isset($_POST['auth'])) 
  6.  { 
  7.      if(isset($_POST['auth']['key'])) 
  8.      { 
  9.          $v_PostedKey = $_POST['auth']['key']
  10.      } 
  11.      if(isset($_POST['auth']['secret'])) 
  12.      { 
  13.          $v_PostedSecret = $_POST['auth']['secret']
  14.      } 
  15.      if($v_PostedKey == $v_Key && $v_PostedSecret == $v_Secret) 
  16.      { 
  17.          mail("This email address is being protected from spambots. You need JavaScript enabled to view it.","Post to AscentCloud","Successful Auth")
  18.      } 
  19.  } 
  20.  // yields: Successful Auth 

Caveat
Unfortunately, I've titled this article as multi-dimensional but I found that this code doesn't support an array nested more than 2 levels deep. In other words, the above solution will not work if I wanted to post the following:
copyraw
{
  "auth": {
    "secret": {
        "word":"can_you_keep_a_secret",
        "fact":"Elephants are the world's largest land animal",
    "key": "aaabbbbccccddddeeeeffff11112222"
  }
}
// using
m_NestedRequest = Map();
m_NestedRequest.put("auth[key]",v_AuthKey);
m_NestedRequest.put("auth[secret][word]","can_you_keep_a_secret");
m_NestedRequest.put("auth[secret][fact]","Elephants are the world's largest land animal");
//
// FAILS !!!  $_POST['auth']['secret']['word'] is NOT set
  1.  { 
  2.    "auth": { 
  3.      "secret": { 
  4.          "word":"can_you_keep_a_secret", 
  5.          "fact":"Elephants are the world's largest land animal", 
  6.      "key": "aaabbbbccccddddeeeeffff11112222" 
  7.    } 
  8.  } 
  9.  // using 
  10.  m_NestedRequest = Map()
  11.  m_NestedRequest.put("auth[key]",v_AuthKey)
  12.  m_NestedRequest.put("auth[secret][word]","can_you_keep_a_secret")
  13.  m_NestedRequest.put("auth[secret][fact]","Elephants are the world's largest land animal")
  14.  // 
  15.  // FAILS !!!  $_POST['auth']['secret']['word'] is NOT set 

Source(s):
Category: Zoho :: Article: 740

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.