Basic CRM integration question - cannot "insertRecords" via the API - error 4600
Hi everyone
I'm trying to do implement a very basic version of a "Add lead" form and am stuck. I tried quite a lot a variants, tried making api calls with the Firefox extension "poster" (https://addons.mozilla.org/en-US/firefox/addon/poster/) and so on but always get the error message:
<response><error><code>4600</code><message>Unable to process your request. Please verify if the name and value is appropriate for the "xmlData" parameter.</message></error></response>
This is the code I'm using, you should be able to copy/paste it and try it yourself.
I even added a hard coded block of xml instead of using the form but I simply don't get it to work, any ideas?
- <!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://s3.amazonaws.com/hayageek/libs/jquery/bootstrap.min.js"></script>
<link href="https://s3.amazonaws.com/hayageek/libs/jquery/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<form name="ajaxform" id="ajaxform" action="" method="POST">
First Name: <input type="text" name="fname" value ="FIRST"/> <br/>
Last Name: <input type="text" name="lname" value ="LAST" /> <br/>
Email : <input type="text" name="email" value="EMAIL"/> <br/>
</form>
Output:<br/>
<button class="btn btn-info" id="simple-post">Run Code</button>
<div id="simple-msg"></div>
<script>
$("#simple-post").click(function()
{
$("#ajaxform").submit(function(e)
{
// NOT using the form at the moment
// var postData = $(this).serializeArray();
// var xmlObject = $('<Leads><row no="1"></row></Leads>');
// $.each( postData, function( i, field ) {
// xmlObject.find('row').first().append('<FL val="'+field.name+'">'+field.value+'</FL>');
// });
var data = {
xmlData:
'<?xml version="1.0" encoding="UTF-8" ?>' +
'<Leads>' +
'<row no="1">' +
'<FL val="Last Name"><![CDATA[TEST]]></FL>' +
'<FL val="Email"><![CDATA[test@test.com]]></FL>' +
'</row>' +
'</Leads>' +
'</xml>'
};
$.ajax(
{
url : "https://crm.zoho.com/crm/private/xml/Leads/insertRecords?authtoken=MYAPIKEY&scope=crmapi",
type: "POST",
data: data,
success:function(data, textStatus, jqXHR)
{
$("#simple-msg").html('<pre><code class="prettyprint">'+data+'</code></pre>');
},
error: function(jqXHR, textStatus, errorThrown)
{
$("#simple-msg").html('<pre><code class="prettyprint">AJAX Request Failed<br/> textStatus='+textStatus+', errorThrown='+errorThrown+'</code></pre>');
}
});
e.preventDefault();
});
$("#ajaxform").submit();
});
</script>
</body>
</html>