Last active
June 2, 2018 18:17
-
-
Save mineta/10018716 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment