Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Brevo/Brevo_Get_contacts.ipynb
2973 views
Kernel: Python 3

Naas

Brevo - Get all the contacts

Give Feedback | Bug report

Tags: #brevo #contacts #get #snippet

Last update: 2024-05-30 (Created: 2024-05-30)

Description: This notebook get all the contacts in Brevo.

Input

Import libraries

import requests import pandas as pd

Setup variables

  • api_key: Brevo API Key

api_key = "YOUR_BREVO_API_KEY"

Model

Get all the contacts

def get_contacts( api_key, limit=100, endpoint="contacts" ): # Init data = [] url = f"https://api.brevo.com/v3/contacts/" headers = { "accept": "application/json", "api-key": api_key } offset = 0 while True: params = { "limit": limit, "offset": offset } res = requests.get(url, headers=headers, params=params) if res.status_code == 200: result = res.json().get(endpoint) data.extend(result) else: break if len(result) == 0 or len(result) < limit: break else: offset += limit return data data = get_contacts(api_key) data[0]

Output

Display results

df = pd.DataFrame(data) print("Rows:", len(df)) df