New leads through API
Hi ,
I am trying to implement a little PHP script to insert new leads into our CRM using the Insightly API and my API key. However, I am unsure how to properly call the API for a lead insertion. The documentation could not clarify it to me.
Woud it be possible to send me a tiny sample PHP code snippet? Or at least some specific pointers on how to accomplish adding new leads through the API.
Thank you so very much.
Sincerely,
Oliver
Comments
Hi Oliver,
This should be pretty easy to do. The PHP library was written by one of our customers, so I think it is a bit out of date by this point.
However, the API is very easy to use. All you need to do is POST a JSON object to the leads endpoint. I recommend you use the Postman extension for Chrome to manually generate requests, as you can see what's going on between the client and server this way.
I also recommend using the GET method to fetch an existing lead, and then you can see what fields the server is expecting.
We will also be releasing version 2.2 of the API today, which has better documentation and online help. Look for that at https://api.insight.ly/v2.2/Help
Thanks,
Brian McConnell
Insightly Engineering Team
Hi there,
I'm trying to create lead via API
My code is:
<?php
$service_url = 'https://api.insight.ly/v2.2/Leads';
$ch = curl_init($service_url);
curl_setopt($ch,
CURLOPT_HTTPHEADER,
array('Content-Type: application/json',
'Authorization: Basic ' . base64_encode('API_KEY')));
curl_close($process);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$data = array(
'FIRST_NAME' => "name",
'LAST_NAME' => "lastname",
'MOBILE_PHONE_NUMBER' => "86666666666",
'EMAIL_ADDRESS' => "email@email.com",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$return = curl_exec($ch);
$err = curl_errno($ch);
$msg = curl_error($ch);
error_log($return);
echo $return;
curl_close($ch);
?>
And i'm getting this error:
[{"Name":"apiLead","Message":"Input string '--------------------------969fa16d17181c0b' is not a valid number. Path '', line 1, position 42."}]
Hi Sergej,
I noticed you're using CURLOPT_HTTPGET in your curl set up. Could you try changing that to CURLOPT_HTTPPOST? When creating new items, use POST and when updating an existing item, use PUT.
Regards,
Sung
Please sign in to leave a comment.