Skip to content

Commit

Permalink
Merge pull request #2152 from jupyter-naas/2145-hubspot-get-activity-…
Browse files Browse the repository at this point in the history
…from-contact-url

2145 hubspot get activity from contact url
  • Loading branch information
FlorentLvr authored Aug 21, 2023
2 parents 6a3fd33 + 4a68aed commit 4a53811
Show file tree
Hide file tree
Showing 15 changed files with 2,072 additions and 1,274 deletions.
85 changes: 30 additions & 55 deletions HubSpot/HubSpot_Delete_note.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"tags": []
},
"source": [
"**Last update:** 2023-04-12 (Created: 2022-05-31)"
"**Last update:** 2023-08-21 (Created: 2022-05-31)"
]
},
{
Expand All @@ -71,7 +71,7 @@
"tags": []
},
"source": [
"**Description:** This template deletes note with a note ID as input."
"**Description:** This notebook demonstrates how to delete a note using its ID using HubSpot API."
]
},
{
Expand Down Expand Up @@ -107,68 +107,35 @@
"outputs": [],
"source": [
"import requests\n",
"import json\n",
"import naas"
]
},
{
"cell_type": "markdown",
"id": "c08dd35d-d963-4bfc-9837-875b679b1d3d",
"id": "2d2120b0-a965-47b9-bbfe-803ef4dc432c",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Setup HubSpot\n",
"👉 Starting November 30, 2022, HubSpot API keys no longer enable access to HubSpot APIs, so in Naas version 2.8.3 and above, you need [create a private app and use the access token](https://developers.hubspot.com/docs/api/private-apps)."
]
},
{
"cell_type": "markdown",
"id": "078ebc00-9cc3-4bc5-b309-b72163cd3310",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"#### Enter Your Access Token"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "36bd049b-d707-4871-8bab-7f592cd9e391",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"HS_ACCESS_TOKEN = naas.secret.get(\"HS_ACCESS_TOKEN\") or \"YOUR_HS_ACCESS_TOKEN\""
]
},
{
"cell_type": "markdown",
"id": "aggressive-trustee",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"#### Setup your note info"
"### Setup variables\n",
"[Get your HubSpot Access token](https://knowledge.hubspot.com/articles/kcs_article/integrations/how-do-i-get-my-hubspot-api-key)\n",
"- `hs_access_token`: This variable stores an access token used for accessing the HubSpot API.\n",
"- `object_id`: This variable stores the object ID."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab201c68-7b10-46b1-a3df-2453f2ad59b5",
"id": "a2b9ba91-140d-43a2-b731-014df55454e8",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"note_id = 19996680052"
"hs_access_token = naas.secret.get(\"HS_ACCESS_TOKEN\") or \"YOUR_HS_ACCESS_TOKEN\"\n",
"object_id = 36918162210"
]
},
{
Expand All @@ -190,7 +157,7 @@
"tags": []
},
"source": [
"### Function to delete note"
"### Delete note"
]
},
{
Expand All @@ -203,18 +170,26 @@
},
"outputs": [],
"source": [
"def delete_note(note_id):\n",
" url = f\"https://api.hubapi.com/crm/v3/objects/notes/{note_id}\"\n",
"def delete_note(\n",
" token,\n",
" object_id\n",
"):\n",
" # Requests\n",
" headers = {\n",
" \"accept\": \"application/json\",\n",
" \"content-type\": \"application/json\",\n",
" \"Content-Type\": \"application/json\",\n",
" \"Authorization\": f\"Bearer {token}\"\n",
" }\n",
" params = {\"limit\": \"100\", \"archived\": \"false\", \"hapikey\": HS_API_KEY}\n",
" # Requests data\n",
" res = requests.delete(url, headers=headers, params=params)\n",
" res.raise_for_status()\n",
" url = f\"https://api.hubapi.com/crm/v3/objects/notes/{object_id}\"\n",
"\n",
" # Response\n",
" res = requests.delete(url, headers=headers)\n",
" if res.status_code == 204:\n",
" print(f\"❎ Note deleted in HubSpot: {note_id}\")"
" print(f\"Note '{object_id}' successfully deleted!\")\n",
" else:\n",
" print(res.text)\n",
" return res\n",
"\n",
"res = delete_note(hs_access_token, object_id)"
]
},
{
Expand Down Expand Up @@ -256,7 +231,7 @@
},
"outputs": [],
"source": [
"delete_note(note_id)"
"res"
]
}
],
Expand Down Expand Up @@ -298,4 +273,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Loading

0 comments on commit 4a53811

Please sign in to comment.