The Close.io API allows you to connect your app or service directly to your data in Close.io to search your existing leads, add new leads, and much more. In this guide, we're going to look at a couple of examples of how to accomplish some basic tasks using the API so that you can get started integrating Close.io into your current apps and workflows.
https://app.close.io/api/v1
curl "https://app.close.io/api/v1/me/" -u yourapikey:
The colon at the end is important, since the key is sent as the username with no corresponding password.
One of the best uses for the Close.io API is searching your data from anywhere. The same options you can use to narrow down your search results within the app are also available as arguments for your search query via the API. For example, let's say you want to view all leads that the latest call direction was inbound. We can construct a query as follows (note the search query is URL encoded):
https://app.close.io/api/v1/lead/?query=latest_call_direction%3AInbound
Next, let's say we want to only show information from that lead that's important to us, such as display name and who created the lead. We can use the _fields paramater to limit that as follows:
https://app.close.io/api/v1/lead/?query=latest_call_direction%3AInbound&_fields=display_name,created_by
So putting this all together to build an API request:
<?php
require_once 'Requests/library/Requests.php';
Requests::register_autoloader();
$headers = array('Content-Type' => 'application/json');
$options = array('auth' => array('YOUR_API_KEY', ''));
$request = Requests::get('https://app.close.io/api/v1/lead/? query=latest_call_direction%3AInbound&_fields=display_name,created_by', $headers, $options);
?>
Another common action is creating a new lead, which can also be accomplished via the Close.io API. As we saw in the previous example of searching, we can use the /lead/
endpoint. In this example, instead of a GET
we'll perform a POST
to that endpoint.
First, we'll need to create an array that contains the information for the new Lead.
$lead = array('lead_name' => 'Close.io', 'contact_name' => 'Steli', 'phone' => '+19998675309');
As you can see, we can use the same field names from searching to create data for our new lead. When we actually write the code to create this lead, we'll encode the $lead
array as JSON for the API to parse.
So, putting all of this together:
<?php
require_once 'Requests/library/Requests.php';
Requests::register_autoloader();
$lead = array('lead_name' => 'Close.io', 'contact_name' => 'Steli', 'phone' => '+19998675309');
$headers = array('Content-Type' => 'application/json');
$options = array('auth' => array('YOUR_API_KEY', ''));
$request = Requests::post('https://app.close.io/api/v1/lead/', $headers, json_encode($lead), $options);
?>
This guide is intended to help you get started with using the Close.io API. While the examples are relatively simple, it illustrates how powerful the API can be and how easy it is to integrate into your existing setup.