Marketing email

Hi

I am using this api https://developers.hubspot.com/docs/methods/cms_email/get-all-marketing-emails to get the marketing and below is my code similar to contacts API,

as per the refference link i have to send previous calls limit as the offset in next call , i did it but i am getting same responce in each call. can someone please let me know how to fix this.

parameters = urllib.parse.urlencode(parameter_dict)get_url = get_all_contacts_url + parametersprint(get_url)response_dict = requests.get(url=get_all_contacts_url, headers=headers).json()marketing_campaign_list.extend(response_dict['objects'])parameter_dict['Offset'] = response_dict['limit']print(response_dict)

Hi @yellalingh,

The offet mechanism of our Get all marketing emails endpoint works differently from our Contacts API.

When looking to get all the marketing emails using this endpoint the offset value is the limit use on the previous request and so in this case you would need to increase the limit;

E.g.

1. To get the first hundred

https://api.hubspot.com/marketing-emails/v1/emails?hapikey=hapikey&limit=100

2. The next page of another hundred

https://api.hubspot.com/marketing-emails/v1/emails?hapikey=hapikey&limit=200&offset=100

3. The third page of another hundred

https://api.hubspot.com/marketing-emails/v1/emails?hapikey=hapikey&limit=300&offset=200

Based on your code, it looks to me that the limit wasn’t set to increase and so I would expect you to get the same response after each call.

Hi @WendyGoh

Can you please help which API i can use to relate marketing campaigns and email campaigns, we usually have marketing campaigns on the top, under each marketing campaigns we have multiple email campaigns. my final goal is to get the email campaign events for each marketing campaign. to get email events i am using email events API which returns email campaign id as one of the parmaeter in responce. now i want relate this email events with the marketing campaign.

Hey @yellalingh,

You can use the Get all marketing emails or Get the details for a marketing email where the response body would return the allEmailCampaignIds parameter.

You can use the id on the Email Events Overview | Email Events API.

Hope this helps to further clarify things!

Hi @WendyGoh

thanks for the responce I have tried this API https://developers.hubspot.com/docs/methods/cms_email/get-all-marketing-emails my portal id is 52600

I have only around 250 marketing campaigns in the application where as i am getting responce of more than 1000, some marketing campaigns are duplicated.

My assumption: may be after itterating through once over all the marketing campaigns, its restarting, Consider a case of an application with 150 marketing campaigns, if request is made with limit of 100, first responce will give first 100, and second call will give remaining 50 pluse, 50 from the begining. if this is a case this can be dealt by using the terminating condition for the request.Can you please let me know what should be terminating condition for the request?

Hey @yellalingh,

In this case, you would need to use both the totalCount and limit set as the counter e.g. if there’s a totalCount of 150 and the limit for each request is 100, the total times that you’d need to loop through the endpoint is 2. You can deduce this by taking 150/100 and round up the number.

Hi @WendyGoh

today I was testing my result and found i couldn’t fetch all the marketing campaigns. there are few ,marrketing campaigns missed. i.e “8ee55337-50f5-454e-a8dd-6b4f769365c1”

get_url = get_all_contacts_url + parameters

print(get_url)

r = requests.get(url= get_url, headers = headers)

response_dict = json.loads(r.text)

max_results = response_dict[‘total’]

marketing_list.extend(response_dict[‘objects’])

parameter_dict[‘offset’] = response_dict[‘limit’]

parameter_dict[‘limit’] = response_dict[‘limit’] + 100

if len(marketing_list) >= max_results: # Exit pagination, based on whatever value you’ve set your max results variable to.

marketing_campaigns = json_normalize(marketing_list)

print(‘maximum number of results exceeded’)

break

request URL’s are as suggested by you on 16 december, please help me fix this. I have arround 250 distinct marketing campaigns api returns only 24 distinct campaigns with the terminating condition suggested by you in previous reply

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=***********&limit=100

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=***********&limit=200&offset=100

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=***********&limit=300&offset=200

Hi @WendyGoh

today I was testing my result and found i couldn’t fetch all the marketing campaigns. there are few ,marrketing campaigns missed. i.e “8ee55337-50f5-454e-a8dd-6b4f769365c1”

get_url = get_all_contacts_url + parameters

print(get_url)

r = requests.get(url= get_url, headers = headers)

response_dict = json.loads(r.text)

max_results = response_dict[‘total’]

marketing_list.extend(response_dict[‘objects’])

parameter_dict[‘offset’] = response_dict[‘limit’]

parameter_dict[‘limit’] = response_dict[‘limit’] + 100

if len(marketing_list) >= max_results: # Exit pagination, based on whatever value you’ve set your max results variable to.

marketing_campaigns = json_normalize(marketing_list)

print(‘maximum number of results exceeded’)

break

request URL’s are as suggested by you on 16 december, please help me fix this. I have arround 250 distinct marketing campaigns api returns only 24 distinct campaigns with the terminating condition suggested by you in previous reply

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=***********&limit=100

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=***********&limit=200&offset=100

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=***********&limit=300&offset=200

Hey @yellalingh,

When I attempt to filter the email by campaign id 8ee55337-50f5-454e-a8dd-6b4f769365c with the following parameter on Get all marketing emails endpoint:

&campaign=8ee55337-50f5-454e-a8dd-6b4f769365c1

I received no email data. This leads me to believe that there’s no email associated with this campaign and so I double checked this by looking into your portal 52xxxx > Marketing > Planning and Strategy > Campaigns > Locate campaign 8ee55337-50f5-454e-a8dd-6b4f769365c > I was able to confirm that there’s no email associated with this campaign.

This is likely why when you run the Get all marketing emails endpoint, you’re not seeing campaign 8ee55337-50f5-454e-a8dd-6b4f769365c1 in the response body.

Hope this helps to clarify things and if you’re seeing a campaign that has associated email but isn’t showing on the Get all marketing emails endpoint, please do let me know.

Hi @WendyGoh

Thanks Wendy, for clarification, it worked however i had make a slight change in the get request, below is the request sample

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=********&limit=100&offset=0

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=********&limit=100&offset=100

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=********&limit=100&offset=200

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=********&limit=100&offset=300

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=********&limit=100&offset=400

https://api.hubapi.com/marketing-emails/v1/emails?hapikey=********&limit=100&offset=500

Once again thanks a lot for the support