# Update engagement task status in nodejs

**URL:** <https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441>\
**Category:** APIs & Integrations\
**Tags:** developer-tools, contacts\
**Created:** [March 1, 2021, 3:10am UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441 "2021-03-01T03:10:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PCarlson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pcarlson/32/35493_2.png) [@PCarlson](https://community.hubspot.com/u/PCarlson)\
**Post date:** [March 1, 2021, 3:10am UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/1 "2021-03-01T03:10:19Z")

</div>

I have not yet succeeded in updating an existing engagement from nodejs. Specifically, I am simply trying to update a specific task status to COMPLETED.

I don’t see any samples that update engagements.

My code looks like this:

```lia-code-sample
 const apiOptions = {
 path: '/engagements/v1/engagements/'+id,
 method: 'POST',
 body: {
 "metadata": {
 status: 'COMPLETED',
 }
 }
 }
 await this._client.apiRequest(apiOptions)

```

Anyone see anything I’m doing wrong?

Thanks

Phil

---

<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:** [March 1, 2021, 6:00pm UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/2 "2021-03-01T18:00:30Z")

</div>

Heyo @PCarlson

Wonder if you need to wrap status.

`"status": "COMPLETED"`

---

<div class="post-metadata">

**Author:** ![PCarlson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pcarlson/32/35493_2.png) [@PCarlson](https://community.hubspot.com/u/PCarlson)\
**Post date:** [March 7, 2021, 8:16pm UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/3 "2021-03-07T20:16:33Z")

</div>

Wrapping status does not fix. I’ll do more experiments today.

---

<div class="post-metadata">

**Author:** ![PCarlson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pcarlson/32/35493_2.png) [@PCarlson](https://community.hubspot.com/u/PCarlson)\
**Post date:** [March 7, 2021, 9:31pm UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/4 "2021-03-07T21:31:39Z")

</div>

Not making much progress. Per [Update an Engagement](https://legacydocs.hubspot.com/docs/methods/engagements/update_engagement-patch) in the legacy api docs, engagement is required in the JSON body, so I tried adding an engagement with various info from the existing engagement and even an empty engagement section like this:

```lia-code-sample
 const apiOptions = {
 path: '/engagements/v1/engagements/'+id,
 method: 'POST',
 body: {
 "engagement": {
 },
 "metadata": {
 "status": 'COMPLETED',
 }
 }
 }

```

But no matter what I try, the response is always: “HttpError: HTTP request failed” giving no clues to what is wrong with the request. So it seems to be a matter of empirical testing to guess what might be expected. But I have not found the magic incantation yet.

Phil

---

<div class="post-metadata">

**Author:** ![PCarlson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pcarlson/32/35493_2.png) [@PCarlson](https://community.hubspot.com/u/PCarlson)\
**Post date:** [March 7, 2021, 10:48pm UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/5 "2021-03-07T22:48:08Z")

</div>

I get the same “HttpError: HTTP request failed” trying to update the engagement due date “timestamp”, so it appears all my updates are failing. Here is my JSON for that attempt:

```lia-code-sample
 const apiOptions = {
 path: '/engagements/v1/engagements/'+id,
 method: 'POST',
 body: {
 "engagement": {
 "timestamp": moment(dueDate).valueOf(), // HubSpot requires timestamp in milliseconds
 },
 }
 }
 await this._client.apiRequest(apiOptions)

```

So I’m either doing something fundamentally wrong or this api through nodejs is broken.

Note I can successfully get activity information using the id in the same manner with this code:

```lia-code-sample
 const apiOptions = {
 path: '/engagements/v1/engagements/' + id,
 }
 await this._client.apiRequest(apiOptions)

```

I can also create an engagement note (and task and call and email) successfully like this:

```lia-code-sample
 const apiOptions = {
 path: '/engagements/v1/engagements',
 method: 'POST',
 body: {
 engagement: {
 active:true,
 type:"NOTE",
 timestamp: moment().valueOf(),
 },
 associations: {
 contactIds: [whoId],
 },
 metadata: {
 body:newDescription,
 }
 }
 };
 await this._client.apiRequest(apiOptions)

```

So both GET and POST calls are working and my oauth token is getting passed by nodejs without putting anything in the JSON. It seems to be specific to Update.

Phil

---

<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:** [March 8, 2021, 10:30pm UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/6 "2021-03-08T22:30:33Z")

</div>

@kierana loves to be distracted so he can procrastinate on. Maybe he has some thoughts

---

<div class="post-metadata">

**Author:** ![kierana](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kierana/32/44503_2.png) [@kierana](https://community.hubspot.com/u/kierana)\
**Post date:** [March 8, 2021, 10:43pm UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/7 "2021-03-08T22:43:31Z")

</div>

Looks like you’re using POST when the API mentions that you need to PATCH.

---

<div class="post-metadata">

**Author:** ![PCarlson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pcarlson/32/35493_2.png) [@PCarlson](https://community.hubspot.com/u/PCarlson)\
**Post date:** [March 13, 2021, 2:55am UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/8 "2021-03-13T02:55:37Z")

</div>

Thanks @kierana , I’ll play with that this weekend. I have seen PATCH referenced in the API docs, but I did not understand it as a method in the endpoints. I’ll post what I find.

Phil

---

<div class="post-metadata">

**Author:** ![PCarlson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pcarlson/32/35493_2.png) [@PCarlson](https://community.hubspot.com/u/PCarlson)\
**Post date:** [March 14, 2021, 8:05pm UTC](https://community.hubspot.com/t/update-engagement-task-status-in-nodejs/32441/9 "2021-03-14T20:05:17Z")

</div>

PATCH did the trick. Thanks @kierana

For reference, my apiOptions looked like this:

```lia-code-sample
 const apiOptions = {
 path: '/engagements/v1/engagements/'+id,
 method: 'PATCH',
 body: {
 "engagement": {
 },
 "metadata": {
 "status": "COMPLETED",
 }
 }
 }

```

Phil
