APIs & Integrations

Eddie_Z
Member

Create a note on Contacts with engagement API

Hi guys,

I am trying to create a note on contacts by using engagement API, I am using Python
Here is my code:

    url = "https://api.hubapi.com/engagements/v1/engagements?access_token=my-token"
    payload = {}
    # engagement
    payload["engagement"] = {}
    payload["engagement"]["active"] = True
    payload["engagement"]["ownerId"] = 9999561
    payload["engagement"]["type"] = "NOTE"
    payload["engagement"]["timestamp"] = 1457973595049
    # associations
    payload["associations"] = {}
    payload["associations"]["contactIds"] = [contact_id]
    payload["associations"]["companyIds"] = []
    payload["associations"]["dealIds"] = []
    payload["associations"]["ownerIds"] = []
    # netadata
    payload["metadata"] = {}
    payload["metadata"]["body"] = "Testing Note"
    response = requests.post(url, data = payload)

somehow it gives my response 415 error:
415 Client Error: Unsupported Media Type for url: https://api.hubapi.com/engagements/v1/engagements?access_token=my-token

0 Upvotes
3 Replies 3
Eddie_Z
Member

Create a note on Contacts with engagement API

Hi @zwolfson ,

Thanks for your reply, after adding headers, I am getting response 400 error:
400 Client Error: Bad Request for url: https://api.hubapi.com/engagements/v1/engagements?access_token=my-token

and the error is:
{“status”:“error”,“message”:“Invalid input JSON on line 1, column 14: Unrecognized token ‘associations’: was expecting (‘true’, ‘false’ or ‘null’)”,“correlationId”:“5ed0a8f4-4318-4854-a15d-855db56d6d4d”,“requestId”:“ec25612d-2a56-41a0-b5a2-0b5c8f1a4299”}

0 Upvotes
zwolfson
HubSpot Employee
HubSpot Employee

Create a note on Contacts with engagement API

Hi @Eddie_Z,

I believe all you need to do is set the header to be Content-Type: Application JSON. So you should add

#set headers
headers = {}
headers["Content-Type"]="application/json"

Then your last line should look like this:

response = requests.post(url,data=payload,headers=headers

Let me know if that doesn’t work.

-Zack

0 Upvotes
Eddie_Z
Member

Create a note on Contacts with engagement API

@zwolfson
I got it solved, I should pass a string to data instead of json.
Thank you so much for helping me out.