Skip to content

Instantly share code, notes, and snippets.

@philfreo
Created August 4, 2015 23:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philfreo/acb785408e6ec1394807 to your computer and use it in GitHub Desktop.
Save philfreo/acb785408e6ec1394807 to your computer and use it in GitHub Desktop.
Close.io API Getting Started Guide

Getting Started with the Close.io API

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.

General API Information

Base URL

https://app.close.io/api/v1

Example Request with your API key

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.

Searching

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);

?>

Creating a New Lead

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);
 
 ?>

Conclusion

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment