# Calling SDK - Update Engagement

**URL:** <https://community.hubspot.com/t/calling-sdk-update-engagement/78848>\
**Category:** APIs & Integrations\
**Tags:** developer, crm, calling\
**Created:** [April 6, 2023, 12:06pm UTC](https://community.hubspot.com/t/calling-sdk-update-engagement/78848 "2023-04-06T12:06:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumarb1](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@kumarb1](https://community.hubspot.com/u/kumarb1)\
**Post date:** [April 6, 2023, 12:06pm UTC](https://community.hubspot.com/t/calling-sdk-update-engagement/78848/1 "2023-04-06T12:06:43Z")

</div>

Hello,

I am working on [HubSpot Calling SDK](https://developers.hubspot.com/docs/api/crm/extensions/calling-sdk), for that I have downloded [SDK from GitHub](https://github.com/HubSpot/calling-extensions-sdk/) and followed further steps.

Now, when I start a call, engagement is getting created from below code,

```lia-code-sample
onDialNumber: (data, rawEvent) => {
	appendMsg(data, rawEvent);
	const { phoneNumber } = data;
	state.phoneNumber = phoneNumber;
	window.setTimeout( () => cti.outgoingCall({
			createEngagement: true,
			phoneNumber
		}),
		500
	);
},

```

But, after call end It’s not getting Updated with call durection.

```lia-code-sample
onEndCall: () => {
	window.setTimeout(() => {
		cti.callEnded();
	}, 500);
},

```

Can you please let me know, how to update that within SDK?

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [April 6, 2023, 4:08pm UTC](https://community.hubspot.com/t/calling-sdk-update-engagement/78848/2 "2023-04-06T16:08:05Z")

</div>

Hello @kumarb1

To update the engagement with call duration in the HubSpot Calling SDK, you can use the `updateEngagement` method provided by the SDK.

Here’s an example of how you can update the engagement with call duration:

```lia-code-sample
onEndCall: () => {
	window.setTimeout(() => {
		// Calculate call duration
		const durationInSeconds = Math.floor((Date.now() - state.callStartTime) / 1000);

		// Update engagement with call duration
		cti.updateEngagement({
			engagementId: state.engagementId,
			metadata: {
				call_duration: durationInSeconds
			}
		});

		// End call
		cti.callEnded();
	}, 500);
}

```

In this example, we first calculate the call duration in seconds using the current time and the call start time stored in the `state` object.

We then call the `updateEngagement` method with the engagement ID and the `metadata` object containing the `call_duration` field set to the calculated duration in seconds.

Finally, we call the `callEnded` method to mark the call as ended.

Note that the engagement must have been created with `createEngagement: true` for the `updateEngagement` method to work. If `createEngagement` is set to false, you will need to create the engagement first and then update it with the call duration.

---

<div class="post-metadata">

**Author:** ![kumarb1](https://avatars.discourse-cdn.com/v4/letter/k/8e7dd6/32.png) [@kumarb1](https://community.hubspot.com/u/kumarb1)\
**Post date:** [April 7, 2023, 5:54am UTC](https://community.hubspot.com/t/calling-sdk-update-engagement/78848/3 "2023-04-07T05:54:06Z")

</div>

Hello,

Thank you for the detailed code, but unfortunately, it is not working for me,  
Please take a look at this error,

 ![kumarb1_0-1680846821423.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/2/b/2bcfd1c0f331e162e0fede5b0cac1d19c8eb1506.png)
