morristech
6/2/2018 - 6:17 PM

inboundcycle_total_contacts.py

import urllib2, json
 
# Aquí tienes que poner el valor de tu Clave API
APIKEY_VALUE = "example-api-key-value-0000"

BASE = "https://api.hubapi.com"
 
def get_total_number_of_contacts():
    # Primero, construimos la URL
    endpoint = "/contacts/v1/contacts/statistics"
    url = BASE + endpoint + "?hapikey=" + APIKEY_VALUE
    # Ahora usamos la libreria urllib2 para abrir la URL y leerla
    response = urllib2.urlopen(url).read()
    # La respuesta esta en formato JSON, así que la transformamos
    # a un diccionario Python
    statistics = json.loads(response)
    # Finalmente, retornamos el número total de contactos
    return statistics["contacts"]

print get_total_number_of_contacts()