APIs & Integrations

LF_Ruiz
Member

Marketing emails api endpoint

SOLVE

Hello,

 

We are working with python and HubSpot API, using both the hubspot api library for python and the requests library depending on the endpoint we are using.

 

We have found a roadblock trying to retrieve the marketing emails and tie them to a contact and get the exact action that contact took with the email (either open, click, bounce, etc).Does anyone know if this is possible and if it is, how can make the call/calls?

0 Upvotes
2 Accepted solutions
sylvain_tirreau
Solution
Top Contributor

Marketing emails api endpoint

SOLVE

Hello,

 

You should start there and see if you find a starting point to create your code (list the events and look for clicks and email opens, then use the Email Marketing API and Contacts API to refine the data you need):

https://developers.hubspot.com/docs/reference/api/analytics-and-events/event-analytics

 

View solution in original post

Balaji_Mavlers1
Solution
Participant | Partner
Participant | Partner

Marketing emails api endpoint

SOLVE

Hi @LF_Ruiz 
Yes, this is possible using HubSpot APIs. You’ll need to combine two APIs to achieve this:

Step 1

Use the Email Events API (Legacy) to find out what actions a contact took on marketing emails (e.g., opened, clicked, bounced).

You’ll need the contact’s email address.

import requests

TOKEN = 'your_private_app_token'
headers = {
    'Authorization': f'Bearer {TOKEN}',
    'Content-Type': 'application/json'
}

params = {
    'recipient': 'contact@example.com',
    'limit': 100
}

response = requests.get(
    'https://api.hubapi.com/email/public/v1/events',
    headers=headers,
    params=params
)

for event in response.json().get('events', []):
    print(event['type'], event['emailCampaignId'], event['timestamp'])

 

This will return event types like:

  • Open
  • Click
  • Bounce
  • Unsubscribe

    Step 2

Once you have the emailCampaign id from the events, use the Marketing Emails API v3 to get info about the email (like subject line and send time):

email_id = '123456'  # use emailCampaignId from above
response = requests.get(
    f'https://api.hubapi.com/marketing/v3/emails/{email_id}',
    headers=headers
)

email_data = response.json()
print(email_data['subject'], email_data['publishDate'])

 

Hope this helps...

Balaji
Manager Demand Generation & Brand

Did my post help answer your question? Mark this as a solution.

View solution in original post

0 Upvotes
5 Replies 5
Balaji_Mavlers1
Solution
Participant | Partner
Participant | Partner

Marketing emails api endpoint

SOLVE

Hi @LF_Ruiz 
Yes, this is possible using HubSpot APIs. You’ll need to combine two APIs to achieve this:

Step 1

Use the Email Events API (Legacy) to find out what actions a contact took on marketing emails (e.g., opened, clicked, bounced).

You’ll need the contact’s email address.

import requests

TOKEN = 'your_private_app_token'
headers = {
    'Authorization': f'Bearer {TOKEN}',
    'Content-Type': 'application/json'
}

params = {
    'recipient': 'contact@example.com',
    'limit': 100
}

response = requests.get(
    'https://api.hubapi.com/email/public/v1/events',
    headers=headers,
    params=params
)

for event in response.json().get('events', []):
    print(event['type'], event['emailCampaignId'], event['timestamp'])

 

This will return event types like:

  • Open
  • Click
  • Bounce
  • Unsubscribe

    Step 2

Once you have the emailCampaign id from the events, use the Marketing Emails API v3 to get info about the email (like subject line and send time):

email_id = '123456'  # use emailCampaignId from above
response = requests.get(
    f'https://api.hubapi.com/marketing/v3/emails/{email_id}',
    headers=headers
)

email_data = response.json()
print(email_data['subject'], email_data['publishDate'])

 

Hope this helps...

Balaji
Manager Demand Generation & Brand

Did my post help answer your question? Mark this as a solution.

0 Upvotes
LF_Ruiz
Member

Marketing emails api endpoint

SOLVE

Hi @sylvain_tirreau and @Balaji_Mavlers1! Thanks for your answer! I'm testing it and I have one question that maybe you can solved, How should I write the request to get me all the events related to an specific campaign? 

I already have the campaign ids, base on a list of campaigns ids (using a for loop for example) I would like to get all the events related to it. 

 

The goal with this is not to query all the events everyday, but just to get the campaigns I'm interested in. 

sylvain_tirreau
Top Contributor

Marketing emails api endpoint

SOLVE

Hi @LF_Ruiz ,

 

You can try something like that:

 

https://api.hubapi.com/events/v3/events?objectType=CAMPAIGN&objectId=12345&limit=100

 

The response contains a paging.offset field to paginate; return it in your next call via &offset={offset}

sylvain_tirreau
Solution
Top Contributor

Marketing emails api endpoint

SOLVE

Hello,

 

You should start there and see if you find a starting point to create your code (list the events and look for clicks and email opens, then use the Email Marketing API and Contacts API to refine the data you need):

https://developers.hubspot.com/docs/reference/api/analytics-and-events/event-analytics

 

BérangèreL
Community Manager
Community Manager

Marketing emails api endpoint

SOLVE

Hi @LF_Ruiz and welcome, we are so glad to see you here! 🤗

Great question, thanks for asking the HubSpot Community!

For information, here is the "Marketing Email API" documentation.

I found for you the solution from @Bortami on this post "Get marketing e-mails per Contact" that might be of interest.

I'd love to put you in touch with our Top Experts: Hi @Bortami, @sylvain_tirreau and @zach_threadint do you have suggestions to help @LF_Ruiz, please?

Have a great day and thanks so much in advance for your help! ❤️
Bérangère


HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates.
Learn More.


Saviez vous que la Communauté est disponible en français?
Rejoignez les discussions francophones en changeant votre langue dans les paramètres! !