For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at http://ascentbusiness.co.uk/zoho-support-2.  For larger projects, check our bespoke pricing structure and receive dedicated support from our hands-on project consultants and developers at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at http://ascentbusiness.co.uk.

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: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience 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 bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.