# Create email engagement - NodeJS

**URL:** <https://community.hubspot.com/t/create-email-engagement-nodejs/44283>\
**Category:** APIs & Integrations\
**Tags:** crm\
**Created:** [September 23, 2021, 3:54pm UTC](https://community.hubspot.com/t/create-email-engagement-nodejs/44283 "2021-09-23T15:54:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArnieK](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/arniek/32/30597_2.png) [@ArnieK](https://community.hubspot.com/u/ArnieK)\
**Post date:** [September 23, 2021, 3:54pm UTC](https://community.hubspot.com/t/create-email-engagement-nodejs/44283/1 "2021-09-23T15:54:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [September 24, 2021, 2:15pm UTC](https://community.hubspot.com/t/create-email-engagement-nodejs/44283/2 "2021-09-24T14:15:23Z")

</div>

Hey @ArnieK

I gather that you found the sample on node tab of the dev docs [here.](https://legacydocs.hubspot.com/docs/methods/engagements/create_engagement)

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:

```lia-code-sample
"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"
}

```

---

<div class="post-metadata">

**Author:** ![ArnieK](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/arniek/32/30597_2.png) [@ArnieK](https://community.hubspot.com/u/ArnieK)\
**Post date:** [September 28, 2021, 1:20pm UTC](https://community.hubspot.com/t/create-email-engagement-nodejs/44283/3 "2021-09-28T13:20:16Z")

</div>

Hi @dennisedson,

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

Regards,

Arnold

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [September 27, 2021, 8:29am UTC](https://community.hubspot.com/t/create-email-engagement-nodejs/44283/4 "2021-09-27T08:29:07Z")

</div>

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](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](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.
