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

Naas

Brevo - Get contacts from list

Give Feedback | Bug report

Tags: #brevo #contacts #lists #snippet

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

Description: This notebook get contacts from a list in Brevo.

Input

Import libraries

import requests import pandas as pd

Setup variables

  • api_key: Brevo API Key

  • list_id: Brevo List ID

api_key = "YOUR_BREVO_API_KEY" list_id = 20

Model

Get contacts in a list

def get_contacts_list( api_key, list_id, limit=100, endpoint="contacts" ): # Init data = [] url = f"https://api.brevo.com/v3/contacts/lists/{list_id}/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_list(api_key, list_id) data[0]

Output

Display results

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