diff --git a/HubSpot/HubSpot_Get_meetings_associated_to_contact.ipynb b/HubSpot/HubSpot_Get_meetings_associated_to_contact.ipynb new file mode 100644 index 0000000000..bcbc83e44e --- /dev/null +++ b/HubSpot/HubSpot_Get_meetings_associated_to_contact.ipynb @@ -0,0 +1,291 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "27486f01-77c3-4774-a098-29c706202d62", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "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 +} diff --git a/HubSpot/HubSpot_List_meeting_properties.ipynb b/HubSpot/HubSpot_List_meeting_properties.ipynb new file mode 100644 index 0000000000..3f2d0d436d --- /dev/null +++ b/HubSpot/HubSpot_List_meeting_properties.ipynb @@ -0,0 +1,285 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "27486f01-77c3-4774-a098-29c706202d62", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "85c6497e-923f-41fa-b85b-81f47a5ab9c7", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# HubSpot - List meeting properties" + ] + }, + { + "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 provides access to the list of meeting properties in HubSpot." + ] + }, + { + "cell_type": "markdown", + "id": "0da5ca2d-a6a1-424c-b41f-391428555503", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [HubSpot API Documentation - Properties](https://developers.hubspot.com/docs/api/crm/properties)" + ] + }, + { + "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", + "[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_type`: This variable stores the object type to retrieve properties from." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c89143dd-3769-4167-b397-09f2d4095fe9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "hs_access_token = naas.secret.get(\"HS_ACCESS_TOKEN\") or \"YOUR_HS_ACCESS_TOKEN\"\n", + "object_type = \"meeting\"" + ] + }, + { + "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": [ + "### List meeting properties" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6fdeeb5b-f1f8-49b6-8bae-388d5190053a", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def list_properties(\n", + " api_token,\n", + " object_type\n", + "):\n", + " # Init\n", + " properties = []\n", + " \n", + " # Make a GET request to the HubSpot API to retrieve the list of object properties\n", + " headers = {\n", + " \"Content-Type\": \"application/json\",\n", + " \"Authorization\": f\"Bearer {api_token}\"\n", + " }\n", + " url = f'https://api.hubapi.com/crm/v3/properties/{object_type}'\n", + " response = requests.get(url, headers=headers)\n", + "\n", + " # Check if the request was successful\n", + " if response.status_code == 200:\n", + " properties_data = response.json()\n", + " properties = properties_data['results']\n", + " for prop in properties:\n", + " prop_name = prop['name']\n", + " prop_label = prop['label']\n", + " print(f\"Property Name: {prop_name}\")\n", + " print(f\"Property Label: {prop_label}\")\n", + " print()\n", + " else:\n", + " print(f\"Failed to retrieve meetings properties. Status code: {response.status_code}\")\n", + " print(response.json())\n", + " return properties\n", + "\n", + "properties = list_properties(hs_access_token, object_type)" + ] + }, + { + "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": [ + "print(\"Properties fetched:\", len(properties))\n", + "properties[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 +} diff --git a/HubSpot/HubSpot_Retrieve_meetings.ipynb b/HubSpot/HubSpot_Retrieve_meetings.ipynb new file mode 100644 index 0000000000..6d29b6b6d1 --- /dev/null +++ b/HubSpot/HubSpot_Retrieve_meetings.ipynb @@ -0,0 +1,252 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "27486f01-77c3-4774-a098-29c706202d62", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "85c6497e-923f-41fa-b85b-81f47a5ab9c7", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# HubSpot - Retrieve meetings" + ] + }, + { + "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-07 (Created: 2023-08-07)" + ] + }, + { + "cell_type": "markdown", + "id": "7dcfd269-589b-4199-b521-6884053ff935", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook uses requests to retrieve meetings from HubSpot API. It is usefull for organizations to get information about their meetings." + ] + }, + { + "cell_type": "markdown", + "id": "0da5ca2d-a6a1-424c-b41f-391428555503", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n- [HubSpot API Documentation](https://developers.hubspot.com/docs/api/crm/meetings)\n- [Requests Documentation](https://requests.readthedocs.io/en/master/)" + ] + }, + { + "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": [] + }, + "source": "import requests", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "6c6ed6b8-90b8-4de6-9b34-9f306d01f574", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n- `api_key`: API key to access HubSpot API. [Get your API key](https://knowledge.hubspot.com/articles/kcs_article/integrations/how-do-i-get-my-hubspot-api-key)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c89143dd-3769-4167-b397-09f2d4095fe9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "api_key = \"\"", + "outputs": [] + }, + { + "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": [ + "### Retrieve meetings" + ] + }, + { + "cell_type": "markdown", + "id": "4b31be29-9ea7-421c-903d-19af6ac7b1e9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "Retrieve meetings from HubSpot API using the `api_key` variable." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e765ab29-08d9-4647-995a-1101289e2047", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "url = \"https://api.hubapi.com/crm/v3/objects/meetings\"\nheaders = {\"Content-Type\": \"application/json\", \"Authorization\": f\"Bearer {api_key}\"}\nresponse = requests.get(url, headers=headers)", + "outputs": [] + }, + { + "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": [] + }, + "source": "print(response.json())", + "outputs": [] + }, + { + "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 +} \ No newline at end of file