Broken APIs and other time wasters
By joe
- 2 minutes read - 320 wordsSo I spent the day trying to figure out why my simple form submission which then generated an XML output, and then a subsequent post to Zoho CRM, did not, in fact, work. I was doing this without the Zoho code, just a description of their API. Its an older API, that much is obvious. You talk to it through XML. You post your XML. But you put parameters on the URI to control the post. I reduced my problem down to a very simple test script, that perfectly illustrated the problem.
The code is here:
#!/usr/bin/perl
use v5.14;
use strict;
use warnings FATAL => 'all';
use LWP::UserAgent;
use Data::Dumper;
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
my $zoho_auth_token = 'insert_your_zoho_authtoken_here';
my $xml = < <'EOT';
<leads>
<row no="1">
<fl val="Lead Source">Web Download</fl>
<fl val="Company">scalable</fl>
<fl val="First Name">test1</fl>
<fl val="Last Name">test1</fl>
<fl val="Email">test1@test1.com</fl>
<fl val="Title">test2</fl>
<fl val="Phone">1234567890</fl>
</row>
EOT
my $url;
$url = sprintf 'https://crm.zoho.com/crm/private/xml/Leads/insertRecords?authtoken=%s&scope;=crmapi&newFormat;=1&duplicateCheck;=1',
$zoho_auth_token;
my $result = $ua->post($url , xmlData => $xml);
printf "result = %s\n ",$result->content;
In every case I tried (and I started with this, and moved on to multipart forms, as well as a number of guesses based upon their API specs), I received an error code of 4600, which suggested something was formatted wrong. So I reduced the XML down to a single field, firstname, and tried that. No dice. I finally gave in and sent them a note with the code, asking them how to make it work. Will look later. I tested the retrieve features to pull in some of our other data to test the authtoken. That worked fine. So I know that works. It appears that their server might simply not like LWP generated requests. Or something like that. So tomorrow, I’ll hook this into our DB (either MongoDB, or PostgreSQL), and once we get a hand on the data import, I’ll write a quick ETL layer.