# Bad Request - adding Engagement

**URL:** <https://community.hubspot.com/t/bad-request-adding-engagement/13464>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [March 12, 2019, 5:29pm UTC](https://community.hubspot.com/t/bad-request-adding-engagement/13464 "2019-03-12T17:29:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deadeye](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/deadeye/32/78108_2.png) [@Deadeye](https://community.hubspot.com/u/Deadeye)\
**Post date:** [March 12, 2019, 5:29pm UTC](https://community.hubspot.com/t/bad-request-adding-engagement/13464/1 "2019-03-12T17:29:48Z")

</div>

Hi all

Newbie here.

I’m writing an app to import GoldMine history into Hubspot as completed tasks.

I’ve managed to, as a test create a company, so I know I’m not far away but when I try and add an egagement task I just keep getting Bad Request. Quite frankly this is f’ing useless information but it is what it is.

Here is an example json string I’m building from a SQL query to the GoldMine database:

{  
“engagement”: {  
“active”: true,  
“ownerId”: 1,  
“type”: “TASK”,  
“timestamp”: 130181149200000000  
},  
“associations”: {  
“contactIds”: [  
1  
],  
“companyIds”: [],  
“dealIds”: [],  
“ownerIds”: []  
},  
“metadata”: {  
“body”: “\r\n\r\n \r\n\r\n\r\n\r\n\u0000”,  
“subject”: " (oc:Aurangzeb Khan)",  
“status”: “COMPLETED”,  
“forObjectType”: “CONTACT”  
}  
}

Here is my code:

Dim newTask As New newTask  
Dim onDateTime As DateTime = contHist(“ondatetime”)  
Dim newEngagement As New Engagement  
With newEngagement  
.active = “true”  
.type = “TASK”  
.timestamp = contHist(“ONDATETIME”).ToFileTime  
.ownerId = 1  
End With  
Dim newAssociations As New Associations

With newAssociations  
.contactIds = {1}  
.companyIds = {}  
.dealIds = {}  
.ownerIds = {}  
End With  
Dim newMetaData As New Metadata  
With newMetaData  
.body = contHist(“ConvertedNotes”)  
.subject = contHist(“REF”)  
.status = “COMPLETED”  
.forObjectType = “CONTACT”  
End With  
With newTask  
.engagement = newEngagement  
.associations = newAssociations  
.metadata = newMetaData  
End With

Dim jSonNewTask As String = JsonConvert.SerializeObject(newTask, Formatting.Indented)  
Dim contactContent As New StringContent(jSonNewTask, Encoding.UTF8, “application/json”)

Dim url As String = “[https://api.hubapi.com/engagements/v1/engagements?hapikey=m](https://api.hubapi.com/engagements/v1/engagements?hapikey=3adcdc24-772a-4370-b2a6-67d05b7553fa)yapikey”

Dim client As HttpClient = New HttpClient  
client.BaseAddress = New Uri(url)  
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue(“application/json”))

client.MaxResponseContentBufferSize = 2147483647

client.Timeout = TimeSpan.FromMinutes(5)

Dim response As HttpResponseMessage = client.PostAsync(url, contactContent).GetAwaiter.GetResult

If response.IsSuccessStatusCode Then  
Dim a As String = response.ReasonPhrase  
End If

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [March 13, 2019, 9:01pm UTC](https://community.hubspot.com/t/bad-request-adding-engagement/13464/2 "2019-03-13T21:01:05Z")

</div>

Welcome, @Deadeye.

Happy to help.

Right off the bat, I see a few issues with that payload:

- The timestamp of `130181149200000000` is improperly formatted. Per [this article](https://developers.hubspot.com/docs/faq/how-should-timestamps-be-formatted-for-hubspots-apis), HubSpot’s APIs only accept UNIX _millisecond_ timestamps.
- The `ownerId` of `1` and `contactIds` value of `1` will fail unless you have owner and contact records in your account with exactly those IDs, which do not exist in any account. For the `contactIds` array, I recommend including a `vid` value returned after [creating a contact](https://developers.hubspot.com/docs/methods/contacts/create_contact). For the `ownerId` value, input one of the IDs returned from [this endpoint](https://developers.hubspot.com/docs/methods/owners/get_owners).

---

<div class="post-metadata">

**Author:** ![Deadeye](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/deadeye/32/78108_2.png) [@Deadeye](https://community.hubspot.com/u/Deadeye)\
**Post date:** [March 14, 2019, 5:20pm UTC](https://community.hubspot.com/t/bad-request-adding-engagement/13464/3 "2019-03-14T17:20:16Z")

</div>

Hello Isaac

Thank you for your response.

I updated the contactIds and ownerId and have ensured the timestamp is in the correct format. I now receive a 200 OK which is great and my actions appear in HubSpot.

However, despite my correct timestamps (I check them on [https://www.unixtimestamp.com](https://www.unixtimestamp.com)) all the tasks I add are set to 18/01/1970 23:45.

Here is an example timestamp: 1550750520 which is 02/21/2019 @ 12:02pm however the due date of the task in Hubspot is 18/01/1970 23:45.

Thanks again for your help

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [March 14, 2019, 5:37pm UTC](https://community.hubspot.com/t/bad-request-adding-engagement/13464/4 "2019-03-14T17:37:26Z")

</div>

Hi, @Deadeye.

The timestamp value `1550750520` only corresponds to **2/21/2019 at 12:02 PM (local time)** if the calculator uses _seconds_. If you add three zeros to the end, you will get `1550750520000`, which is the same date and time in _milliseconds_.

---

<div class="post-metadata">

**Author:** ![Deadeye](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/deadeye/32/78108_2.png) [@Deadeye](https://community.hubspot.com/u/Deadeye)\
**Post date:** [March 14, 2019, 5:48pm UTC](https://community.hubspot.com/t/bad-request-adding-engagement/13464/5 "2019-03-14T17:48:01Z")

</div>

Isaac, another great response, thank you.

I have another question if I may - if I should raise a seperate thread then of course I will.

Is it possible to get a contact from a new field I created and imported into using the standard import tool or am I limited to finding a contact by email?

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [March 14, 2019, 6:16pm UTC](https://community.hubspot.com/t/bad-request-adding-engagement/13464/6 "2019-03-14T18:16:47Z")

</div>

Hey, @Deadeye.

Would you actually mind posting again for that question? I’ll try to reply later this afternoon.

For organization and ease-of-use, we usually try to keep threads focused on a single topic or issue.

Thanks for your understanding!
