12.7 C
London
Friday, October 10, 2025

How you can use PHP and cURL to connect Insightly API?

- Advertisement -spot_imgspot_img
- Advertisement -spot_imgspot_img

PHP and cURL are powerful tools that can be used to connect and interact with various APIs, including the Insightly API.

Connecting to the Insightly API using PHP and cURL

PHP and cURL are powerful tools that can be used to connect and interact with various APIs, including the  API. Insightly is a popular customer relationship management (CRM) platform that provides a RESTful API, for developers to integrate and interact with their data. By leveraging PHP and cURL, you can easily send HTTP requests to the API, retrieve data, and perform actions such as creating, updating, or deleting records.

Here’s an example of how you can use PHP and cURL to connect to Insightly API:

<?php
     // Replace YOUR_API_KEY with your actual API key 
     $api_key = 'YOUR_API_KEY'; 
     $headers = array( 
         'Authorization: Basic '.$api_key, 
         'Content-Type: application/json' 
     );

// Initialize cURL 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://api.insight.ly/v2.2/Contacts'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

// Execute the cURL request 
$response = curl_exec($ch);

// Close cURL 
curl_close($ch);

// Decode the JSON response 
$data = json_decode($response, true); 
print_r($data); 
?>

In this example, YOUR_API_KEY is the key you obtained from Insightly, and https://api.insight.ly/v2.2/Contacts is the endpoint for retrieving a list of contacts.

To create a new contact with PHP cURL:

<?php 
     // Replace YOUR_API_KEY with your actual API key 
     $api_key = 'YOUR_API_KEY'; 
     $headers = array( 
           'Authorization: Basic '.$api_key, 
           'Content-Type: application/json' 
     );

     // Specify the data for new contact 
     $new_contact = array("FIRST_NAME"=> "John", "LAST_NAME"=> "Doe"); 
     $payload = json_encode($new_contact);

     // Initialize cURL 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://api.insight.ly/v2.2/Contacts'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

// Execute the cURL request 
$response = curl_exec($ch);

// Close cURL 
curl_close($ch);

// Decode the JSON response 
$data = json_decode($response, true); 
print_r($data); 
?>

As you can see, you can use CURLOPT_POST and CURLOPT_POSTFIELDS to create new contact by posting payload data to the API.

In general, you should always check Insightly documentation for more detailed information on the available endpoints, parameters, etc.

Relative Blogs : How to connect WordPress Contact Form 7 form to your Zoho CRM?

- Advertisement -spot_imgspot_img
Latest news
- Advertisement -spot_img
Related news
- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here