APIs & Integrations

ArnieK
Participant | Elite Partner
Participant | Elite Partner

Create email engagement - NodeJS

SOLVE

Hi everyone,

 

I am trying to develop a NodeJS program to create email engagements on a client's Hubspot. I have done everything but the creation of the engagement. I have found a sample code of a note engagement but I can't find one for email engagements.

 

Does anyone have a solution for this?

 

Thank you in advance,

Arnie

0 Upvotes
1 Accepted solution
dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

Create email engagement - NodeJS

SOLVE

Hey @ArnieK 

I gather that you found the sample on node tab of the dev docs here.

If you go back to the json and look at the example, scroll down to after the note example and you will see the meta that you need for email.   You would replace the note meta that is provided in the node example with the email metadata

Example:

"metadata": {
    "from": {
      "email": "email@domain.com",
      "firstName": "First",
      "lastName": "Last"
    },
    "to": [
      {
        "email": "contact name <test@test.com>"
      }
    ],
    "cc": [],
    "bcc": [],
    "subject": "This is the subject of the email",
    "html": "<div>This is the body of the email</div><div><br></div><div>-Me</div>",
    "text": "This is the body of the email\n\n-Me"
}

View solution in original post

3 Replies 3
webdew
Guide | Diamond Partner
Guide | Diamond Partner

Create email engagement - NodeJS

SOLVE

Hi @ArnieK ,

You can create an email engament with the same api just need to change the object type. consider the following code as an example. var request = require("request");

var options = { method: 'POST',
url: 'https://api.hubapi.com/engagements/v1/engagements',
qs: { hapikey: 'demo' },
headers:
{'Content-Type': 'application/json' },
body:
{ engagement:
{ active: true,
ownerId: 1,
type: 'EMAIL',
timestamp: 1409172644778 },
associations:
{ contactIds: [ 11877974 ],
companyIds: [],
dealIds: [],
ownerIds: [] },
attachments: [ { id: 4241968539 } ],
metadata: { body: 'note body' } },
json: true };

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
}); For more info please refer to this doc:https://legacydocs.hubspot.com/docs/methods/engagements/create_engagement

Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regard.

dennisedson
Solution
HubSpot Product Team
HubSpot Product Team

Create email engagement - NodeJS

SOLVE

Hey @ArnieK 

I gather that you found the sample on node tab of the dev docs here.

If you go back to the json and look at the example, scroll down to after the note example and you will see the meta that you need for email.   You would replace the note meta that is provided in the node example with the email metadata

Example:

"metadata": {
    "from": {
      "email": "email@domain.com",
      "firstName": "First",
      "lastName": "Last"
    },
    "to": [
      {
        "email": "contact name <test@test.com>"
      }
    ],
    "cc": [],
    "bcc": [],
    "subject": "This is the subject of the email",
    "html": "<div>This is the body of the email</div><div><br></div><div>-Me</div>",
    "text": "This is the body of the email\n\n-Me"
}

ArnieK
Participant | Elite Partner
Participant | Elite Partner

Create email engagement - NodeJS

SOLVE

Hi @dennisedson,

 

That is what I found yes but your solution was perfect! Thank you for your help!

 

Regards,

Arnold