Skip to content

Commit

Permalink
Merge pull request #2118 from jupyter-naas/2117-hubspot-retrieve-meet…
Browse files Browse the repository at this point in the history
…ings

feat: HubSpot - Manage meetings
  • Loading branch information
FlorentLvr authored Aug 11, 2023
2 parents c78f877 + bcdf8f2 commit a67bec0
Show file tree
Hide file tree
Showing 3 changed files with 828 additions and 0 deletions.
291 changes: 291 additions & 0 deletions HubSpot/HubSpot_Get_meetings_associated_to_contact.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "27486f01-77c3-4774-a098-29c706202d62",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>"
]
},
{
"cell_type": "markdown",
"id": "85c6497e-923f-41fa-b85b-81f47a5ab9c7",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# HubSpot - Get meetings associated to contact"
]
},
{
"cell_type": "markdown",
"id": "661f554e-7065-4101-81c2-9e799a812b67",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #hubspot #api #meetings #retrieve #requests #python"
]
},
{
"cell_type": "markdown",
"id": "a852a18f-e277-4aa5-bdec-8dd1fccb57d2",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel)"
]
},
{
"cell_type": "markdown",
"id": "6dd7c05c-17ed-459f-88a8-3c6629b80cde",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Last update:** 2023-08-11 (Created: 2023-08-07)"
]
},
{
"cell_type": "markdown",
"id": "7dcfd269-589b-4199-b521-6884053ff935",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Description:** This notebook demonstrates how to retrieve meetings ID associated with a contact in HubSpot using the HubSpot API."
]
},
{
"cell_type": "markdown",
"id": "0da5ca2d-a6a1-424c-b41f-391428555503",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**References:**\n",
"- [HubSpot API - Associations v4](https://developers.hubspot.com/docs/api/crm/associations)"
]
},
{
"cell_type": "markdown",
"id": "8c6e5050-800a-4f05-a1d2-5a682c54e069",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "6c27222b-7468-4daa-9a77-c446aaf66f72",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3fad6df-27f3-4e13-a934-083468860bf3",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"import requests\n",
"import naas"
]
},
{
"cell_type": "markdown",
"id": "6c6ed6b8-90b8-4de6-9b34-9f306d01f574",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Setup variables\n",
"**Mandatory**\n",
"\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",
"- `contact_id`: This variable stores the HubSpot contact ID\n",
"\n",
"**Optional**\n",
"- `endpoint`: Endpoint to be used to get association from contact"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c89143dd-3769-4167-b397-09f2d4095fe9",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"# Mandatory\n",
"hs_access_token = naas.secret.get(\"HS_ACCESS_TOKEN\") or \"YOUR_HS_ACCESS_TOKEN\"\n",
"contact_id = 478901\n",
"\n",
"# Optional\n",
"endpoint = \"meetings\""
]
},
{
"cell_type": "markdown",
"id": "1ff5c82c-f9bb-4591-bbe4-e683317da3df",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "7b5fa0c9-ea58-4117-9445-a421a3189015",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Get meetings associated to contact"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e765ab29-08d9-4647-995a-1101289e2047",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"def get_association_from_contact(\n",
" token,\n",
" contact_id,\n",
" endpoint,\n",
"):\n",
" # Init\n",
" results = []\n",
" \n",
" # Requests\n",
" headers = {\n",
" \"Content-Type\": \"application/json\",\n",
" \"Authorization\": f\"Bearer {token}\"\n",
" }\n",
" url = f\"https://api.hubapi.com/crm/v4/objects/contacts/{contact_id}/associations/{endpoint}\"\n",
" \n",
" # Response\n",
" res = requests.get(url, headers=headers)\n",
" if res.status_code == 200:\n",
" results = res.json().get(\"results\")\n",
" return results\n",
"\n",
"data = get_association_from_contact(\n",
" hs_access_token,\n",
" contact_id,\n",
" endpoint\n",
")\n",
"print(\"Row fetched:\", len(data))"
]
},
{
"cell_type": "markdown",
"id": "6e9729cd-8e75-4c13-a06c-87afb9923e53",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "63a8e638-dafd-45ea-9f7e-a0aec60a8a7d",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Display result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "128d8d7f-f053-40d1-bf45-c8bcfb0ca5f9",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"if len(data) > 0:\n",
" print(data[0])"
]
},
{
"cell_type": "markdown",
"id": "d12c841e-5924-4e79-b565-88295343ba0c",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit a67bec0

Please sign in to comment.