Links
Comment on page

Get no of emails opened

Tags: #sendinblue #emails #campaign #opened #emailcampaigns #marketing #operations #snippet
Last update: 2023-04-12 (Created: 2022-07-09)
Description: This notebook provides a way to track the number of emails opened using Sendinblue.

Input

Import libraries

import requests
import json
import naas

Setup Sendinblue

SENDINBLUE_API_KEY = (
naas.secret.get(name="SENDINBLUE_API_KEY") or "ENTER_YOUR_SENDINBLUE_API_KEY"
)

Variable

campaign_name = "Minura's Campaign"

Model

Send request to Sendinblue API

response = requests.get(
"https://api.sendinblue.com/v3/emailCampaigns",
headers={"Accept": "application/json", "api-key": SENDINBLUE_API_KEY},
)

Output

Get the campaign

campaign = next(
item
for item in json.loads(response.text)["campaigns"]
if item["name"] == campaign_name
)

Get the number of emails viewed (opened)

campaign["statistics"]["globalStats"]["viewed"]