APIs & Integrations

JDiaz22
Participant

Importing Notes or Posting Imported data on Activity per Contact

Hi all im new to this community and wanted to as something about how to import notes:

https://developers.hubspot.com/docs/api/crm/notes
im using above guides to try to import notes and getting response but its not updating the notes on my contacts

 

import requests
import json

url = "https://api.hubapi.com/crm/v3/objects/notes/batch/create"
headers = {
'Content-Type': "application/json",
'Authorization': 'Bearer "bearer here" '
}
payload = json.dumps(
{
"inputs": [
{
"id": "id here",
"properties": {
"hs_note_body": "Test 4",
"hubspot_owner_id": "id here "
}
}
]
}

);


response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

 One thing that i tried and works is the legacy engagement which is straight forward and working. my problem here is i dont know how to post a unique notes per contacts.


https://legacydocs.hubspot.com/docs/methods/engagements/create_engagement 

import requests
import json

url_notes = "https://api.hubapi.com/engagements/v1/engagements"


payload = json.dumps({
"engagement": {
"active": 'true',
"ownerId": 111,
"type": "NOTE"
},
"associations": {
"contactIds": ['222','333']
},
"metadata": {
"body": "test3"
}
});
headers = {
'Content-Type': "application/json",
'Authorization': 'Bearer "bearer here" '
}

response = requests.request("POST", url_notes, data=payload, headers=headers)

print(response.text)


Im not sure if there are better ways aside from what i tried above. but my main goal is to post on activity on each contacts.

JDiaz22_0-1663648693420.png

 

0 Upvotes
2 Replies 2
Jaycee_Lewis
Community Manager
Community Manager

Importing Notes or Posting Imported data on Activity per Contact

Hey, @JDiaz22 👋 I am mostly clear on your goal. Please correct me if I am wrong or miss anything.

 

You are correct, the v1 version of this endpoint allows you to create the note and associate it to a Contact in a single call. Here's a quick test:

Request

POST https://api.hubapi.com/engagements/v1/engagements

JSON Body
{
    "engagement": {
        "active": true,
        "type": "NOTE",
        "timestamp": 1658247956001
    },
    "associations": {
        "contactIds": [
            301
        ]
    },
    "metadata": {
        "body": "Tacos!"
    }
}

Response

{
    "associationCreateFailures": [],
    "engagement": {
        "id": 25871672710,
        "portalId": 22245342,
        "active": true,
        "createdAt": 1663705895783,
        "lastUpdated": 1663705895783,
        "type": "NOTE",
        "timestamp": 1658247956001,
        "allAccessibleTeamIds": [],
        "bodyPreview": "Tacos!",
        "queueMembershipIds": [],
        "bodyPreviewIsTruncated": false,
        "bodyPreviewHtml": "<html>\n <head></head>\n <body>\n Tacos!\n </body>\n</html>"
    },
    "associations": {
        "contactIds": [
            301
        ],
        "companyIds": [],
        "dealIds": [],
        "ownerIds": [],
        "workflowIds": [],
        "ticketIds": [],
        "contentIds": [],
        "quoteIds": []
    },
    "attachments": [],
    "metadata": {
        "body": "Tacos!"
    }
}

CleanShot 2022-09-20 at 14.41.53.png

 

Otherwise, the v3 Engagements > Notes endpoints allow for the same result, but requires the creation and the association to be split into two calls:

1.

POST /crm/v3/objects/notes

2.

PUT /crm/v3/objects/notes/{noteId}/associations/{toObjectType}/{toObjectId}/{associationType}

 

Please note, the Legacy endpoints should be considered stable and supported unless explicitly noted on the endpoint page. In this case, if the legacy endpoint works for you and your goal, you can be confided it is supported and maintained. 

 

Have fun building! — Jaycee

 

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

JDiaz22
Participant

Importing Notes or Posting Imported data on Activity per Contact

hi @Jaycee_Lewis thank you very much for the response! was actually looking for way to batch update the notes on multiple contacts and the v1/engagements (if im correct about it) only allows one a time and will require a loop and consume alot of request.post().

was looking for a sample on how to use the /objects/notes since when i tried to post something it response error but nothing happend, i assume my payload or somewhere on my script is incorrect. But as you mentioned on your repl it seems im doing it incorrectly. 
below is the script that i tried before i tested posting here, if its possible to draft a correct sample from below template i would highly appreciate it

import requests
import json


url = "https://api.hubapi.com/crm/v3/objects/notes/batch/create"
headers = {
'Content-Type': "application/json",
'Authorization': 'Bearer "bearer here" '
}
payload = json.dumps(
{
"inputs": [
{
"id": "id 1 here",
"properties": {
"hs_note_body": "Test 4",
"hubspot_owner_id": "id here "
}
},
{
"id": "id 2 here ",
"properties": {
"hs_note_body": "Test 4",
"hubspot_owner_id": "id here "
}
}

]
}

);



0 Upvotes