Skip to content

Instantly share code, notes, and snippets.

@lancejohnson
Created August 26, 2020 17:02
Show Gist options
  • Save lancejohnson/170bd89ccda2a1b841a4e1a1944520c9 to your computer and use it in GitHub Desktop.
Save lancejohnson/170bd89ccda2a1b841a4e1a1944520c9 to your computer and use it in GitHub Desktop.
I frequently need an easy way to count the number of leads that match a given query in Close CRM. This is a quick way to do that. See Close CRM docs for more help https://developer.close.com/#leads
from os import environ
import requests
from requests.auth import HTTPBasicAuth
CLOSE_API_KEY = environ.get("CLOSE_API_KEY", "")
BASE_URL = "https://api.close.com/api/v1/lead/"
PARAMS = {"query": """(original_lead_status:"stat_pdBqiRfX6DrpDrE8v320qT2tCSSNURza5cv8aSWxdcp" and created >= "2020-06-01 00:00:00" and created <= "2020-06-30 23:59:59") or lead_status_change(new_status:"stat_pdBqiRfX6DrpDrE8v320qT2tCSSNURza5cv8aSWxdcp" and date >= "2020-06-01 00:00:00" and date <= "2020-06-30 23:59:59")"""}
resp = requests.get(BASE_URL, params=PARAMS, auth=HTTPBasicAuth(CLOSE_API_KEY, ""))
num_of_results = resp.json()["total_results"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment