APIs & Integrations

IHaida
Participant

Error while creating email via API

SOLVE

When I create the email via API I have to add hubspot_owner_id, which is reflected as email author in the interface.

 

Today I faced the issue, that no matten which hubspot_owner_id I post, I receive the error.

 

Here is the sample request and response

curl --request POST \
--url https://api.hubspot.com/crm/v3/objects/emails \
--header 'Authorization: Bearer *********************************' \
--header 'Content-Type: application/json' \
--data '{
"properties": {
"hs_timestamp": "2019-10-30T03:30:17.883Z",
"hubspot_owner_id": "28420727",
"hs_email_direction": "EMAIL",
"hs_email_status": "SENT",
"hs_email_subject": "Lets talk",
"hs_email_text": "Thanks for your interest lets find a time to connect"
}
}'

Response:

{
"status": "error",
"message": "Property values were not valid: [{\"isValid\":false,\"message\":\"28420727 was not a valid owner ID\",\"error\":\"INVALID_OWNER_ID\",\"name\":\"hubspot_owner_id\"}]",
"correlationId": "1734a9c2-db7d-4396-ae86-51883ac201a9",
"category": "VALIDATION_ERROR"
}

 

Can somebody help with this?

0 Upvotes
1 Accepted solution
Jaycee_Lewis
Solution
Community Manager
Community Manager

Error while creating email via API

SOLVE

Hey, @IHaida 👋 Thanks for the interesting question. For this engagement endpoint, you need to make sure you are using the Owner ID and not the User ID when you send your request. It got me on my first test as well. Here's what I did:

First I tried using the User ID (not remembering these are two separate values) 🙃
User ID 

user_ID.png

Owner ID 

owner_ID.png

Request (not successful)

curl --request POST \
  --url https://api.hubapi.com/crm/v3/objects/emails \
  --header 'authorization: Bearer MY_PRIVATE_APP' \
  --header 'content-type: application/json' \
  --data '{
  "properties": {
    "hs_timestamp": "2019-10-30T03:30:17.883Z",
    "hubspot_owner_id": "10029778",
    "hs_email_direction": "EMAIL",
    "hs_email_status": "SENT",
    "hs_email_subject": "Lets talk",
    "hs_email_text": "Thanks for your interest. Lets find a time to connect about cats"
  }
}'

Response

HTTP 400
{
  "status": "error",
  "message": "Property values were not valid: [{\"isValid\":false,\"message\":\"10029778 was not a valid owner ID\",\"error\":\"INVALID_OWNER_ID\",\"name\":\"hubspot_owner_id\"}]",
  "correlationId": "5d58e23b-3e6e-4899-962f-d2cd9aa3e088",
  "category": "VALIDATION_ERROR"
}


But when I switched to Owner ID 

curl --request POST \
  --url https://api.hubapi.com/crm/v3/objects/emails \
  --header 'authorization: Bearer MY_PRIVATE_APP' \
  --header 'content-type: application/json' \
  --data '{
  "properties": {
    "hs_timestamp": "2019-10-30T03:30:17.883Z",
    "hubspot_owner_id": "199431518",
    "hs_email_direction": "EMAIL",
    "hs_email_status": "SENT",
    "hs_email_subject": "Lets talk",
    "hs_email_text": "Thanks for your interest. Lets find a time to connect about cats"
  }
}'

Response

HTTP 201

{
  "id": "24364730256",
  "properties": {
    "hs_all_owner_ids": "199431518",
    "hs_body_preview": "Thanks for your interest. Lets find a time to connect about cats",
    "hs_body_preview_html": "Thanks for your interest. Lets find a time to connect about cats",
    "hs_body_preview_is_truncated": "false",
    "hs_createdate": "2022-08-08T00:48:19.468Z",
    "hs_email_attached_video_opened": "false",
    "hs_email_attached_video_watched": "false",
    "hs_email_direction": "EMAIL",
    "hs_email_status": "SENT",
    "hs_email_subject": "Lets talk",
    "hs_email_text": "Thanks for your interest. Lets find a time to connect about cats",
    "hs_lastmodifieddate": "2022-08-08T00:48:19.468Z",
    "hs_object_id": "24364730256",
    "hs_timestamp": "2019-10-30T03:30:17.883Z",
    "hs_user_ids_of_all_owners": "10029778",
    "hubspot_owner_assigneddate": "2022-08-08T00:48:19.468Z",
    "hubspot_owner_id": "199431518"
  },
  "createdAt": "2022-08-08T00:48:19.468Z",
  "updatedAt": "2022-08-08T00:48:19.468Z",
  "archived": false
}

 

Please note, if you need to access the owner IDs via API, we offer the Owners API:

GET /crm/v3/owners/

 

I hope this helps get you moving forward.

 

Have fun coding! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

View solution in original post

0 Upvotes
2 Replies 2
Jaycee_Lewis
Solution
Community Manager
Community Manager

Error while creating email via API

SOLVE

Hey, @IHaida 👋 Thanks for the interesting question. For this engagement endpoint, you need to make sure you are using the Owner ID and not the User ID when you send your request. It got me on my first test as well. Here's what I did:

First I tried using the User ID (not remembering these are two separate values) 🙃
User ID 

user_ID.png

Owner ID 

owner_ID.png

Request (not successful)

curl --request POST \
  --url https://api.hubapi.com/crm/v3/objects/emails \
  --header 'authorization: Bearer MY_PRIVATE_APP' \
  --header 'content-type: application/json' \
  --data '{
  "properties": {
    "hs_timestamp": "2019-10-30T03:30:17.883Z",
    "hubspot_owner_id": "10029778",
    "hs_email_direction": "EMAIL",
    "hs_email_status": "SENT",
    "hs_email_subject": "Lets talk",
    "hs_email_text": "Thanks for your interest. Lets find a time to connect about cats"
  }
}'

Response

HTTP 400
{
  "status": "error",
  "message": "Property values were not valid: [{\"isValid\":false,\"message\":\"10029778 was not a valid owner ID\",\"error\":\"INVALID_OWNER_ID\",\"name\":\"hubspot_owner_id\"}]",
  "correlationId": "5d58e23b-3e6e-4899-962f-d2cd9aa3e088",
  "category": "VALIDATION_ERROR"
}


But when I switched to Owner ID 

curl --request POST \
  --url https://api.hubapi.com/crm/v3/objects/emails \
  --header 'authorization: Bearer MY_PRIVATE_APP' \
  --header 'content-type: application/json' \
  --data '{
  "properties": {
    "hs_timestamp": "2019-10-30T03:30:17.883Z",
    "hubspot_owner_id": "199431518",
    "hs_email_direction": "EMAIL",
    "hs_email_status": "SENT",
    "hs_email_subject": "Lets talk",
    "hs_email_text": "Thanks for your interest. Lets find a time to connect about cats"
  }
}'

Response

HTTP 201

{
  "id": "24364730256",
  "properties": {
    "hs_all_owner_ids": "199431518",
    "hs_body_preview": "Thanks for your interest. Lets find a time to connect about cats",
    "hs_body_preview_html": "Thanks for your interest. Lets find a time to connect about cats",
    "hs_body_preview_is_truncated": "false",
    "hs_createdate": "2022-08-08T00:48:19.468Z",
    "hs_email_attached_video_opened": "false",
    "hs_email_attached_video_watched": "false",
    "hs_email_direction": "EMAIL",
    "hs_email_status": "SENT",
    "hs_email_subject": "Lets talk",
    "hs_email_text": "Thanks for your interest. Lets find a time to connect about cats",
    "hs_lastmodifieddate": "2022-08-08T00:48:19.468Z",
    "hs_object_id": "24364730256",
    "hs_timestamp": "2019-10-30T03:30:17.883Z",
    "hs_user_ids_of_all_owners": "10029778",
    "hubspot_owner_assigneddate": "2022-08-08T00:48:19.468Z",
    "hubspot_owner_id": "199431518"
  },
  "createdAt": "2022-08-08T00:48:19.468Z",
  "updatedAt": "2022-08-08T00:48:19.468Z",
  "archived": false
}

 

Please note, if you need to access the owner IDs via API, we offer the Owners API:

GET /crm/v3/owners/

 

I hope this helps get you moving forward.

 

Have fun coding! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
coldrickjack
Top Contributor

Error while creating email via API

SOLVE

Hi @IHaida,

 

I don't think the endpoint you are calling is valid. Or at least it's certainly not one that I am familiar with. I cannot find it documented anywhere on the HubSpot Developer site. It's true you can create marketing emails via API but this is done using the v1 endpoint here and it does not require you to specify an owner ID. For instance:

 

curl --location --request POST 'https://api.hubapi.com/marketing-emails/v1/emails' 
--header 'Authorization: Bearer XXXXXXXXXXXX'
--header 'Content-Type: application/json'
--data-raw '{
"name": "My first API marketing email!",
"subject": "Sample subject line"
}'

Returns the below and for the most part if you include any of the below in your initial POST request you can set create the email with various pieces of information preset and ready to go.

 

{
"ab": false,
"abHoursToWait": 4,
"abSampleSizeDefault": null,
"abSamplingDefault": null,
"abSuccessMetric": null,
"abTestPercentage": 50,
"abVariation": false,
"absoluteUrl": "http://xxxxxx.hs-sites-eu1.com/-temporary-slug-bc511b85-a54d-40dd-933a-b77f16bd2956",
"allEmailCampaignIds": [],
"analyticsPageId": "51526178296",
"analyticsPageType": "email",
"archived": false,
"archivedAt": 0,
"archivedInDashboard": false,
"audienceAccess": "PUBLIC",
"blogRssSettings": null,
"canSpamSettingsId": 51418157807,
"categoryId": 2,
"contentAccessRuleIds": [],
"contentAccessRuleTypes": [],
"contentTypeCategory": 2,
"createPage": false,
"created": 1659701891943,
"createdById": 46163190,
"currentState": "DRAFT",
"currentlyPublished": false,
"customReplyTo": "",
"customReplyToEnabled": false,
"domain": "",
"emailBody": "{% content_attribute \"email_body\" %}{{ default_email_body }}{% end_content_attribute %}",
"emailNote": "",
"emailTemplateMode": "DESIGN_MANAGER",
"emailType": "BATCH_EMAIL",
"feedbackSurveyId": null,
"flexAreas": {},
"freezeDate": 1659701891943,
"fromName": "",
"hasContentAccessRules": false,
"htmlTitle": "",
"id": 51526178296,
"isGraymailSuppressionEnabled": true,
"isPublished": false,
"isRecipientFatigueSuppressionEnabled": null,
"language": "en",
"layoutSections": {},
"liveDomain": "xxxxxxx.hs-sites-eu1.com",
"mailingListsExcluded": [],
"mailingListsIncluded": [],
"maxRssEntries": 5,
"metaDescription": "",
"name": "My first API marketing email!",
"pageExpiryEnabled": false,
"pageRedirected": false,
"pastMabExperimentIds": [],
"portalId":xxxxxxx,
"previewKey": "VsCBuisB",
"processingStatus": "",
"publishDate": 1659701892042,
"publishImmediately": true,
"publishedUrl": "",
"replyTo": "",
"resolvedDomain": "xxxxxxx.hs-sites-eu1.com",
"rssEmailByText": "By",
"rssEmailClickThroughText": "Read more »",
"rssEmailCommentText": "Comment »",
"rssEmailEntryTemplateEnabled": false,
"rssEmailImageMaxWidth": 0,
"rssEmailUrl": "",
"sections": {},
"securityState": "NONE",
"slug": "-temporary-slug-bc511b85-a54d-40dd-933a-b77f16bd2956",
"smartEmailFields": null,
"state": "DRAFT",
"styleSettings": null,
"subcategory": "batch",
"subject": "Sample subject line",
"subscription": 148019002,
"subscriptionName": "test",
"teamPerms": [],
"templatePath": "",
"transactional": false,
"translations": {},
"unpublishedAt": 0,
"updated": 1659701891943,
"updatedById": 46163190,
"url": "http://xxxxxxx.hs-sites-eu1.com/-temporary-slug-bc511b85-a54d-40dd-933a-b77f16bd2956",
"useRssHeadlineAsSubject": false,
"userPerms": [],
"vidsExcluded": [],
"vidsIncluded": [],
"widgets": {}
}

 

0 Upvotes