From ca45f3e47f40cc768e6b1368043c9a1adc72fca9 Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 4 Jan 2024 17:30:03 +0100 Subject: [PATCH] feat: add notes templates --- Pipedrive/Pipedrive_Get_a_note.ipynb | 291 +++++++++++++++++++ Pipedrive/Pipedrive_Get_all_notes.ipynb | 332 ++++++++++++++++++++++ Pipedrive/Pipedrive_Update_a_deal.ipynb | 296 +++++++++++++++++++ Pipedrive/Pipedrive_Update_a_note.ipynb | 292 +++++++++++++++++++ Pipedrive/Pipedrive_Update_a_person.ipynb | 6 +- 5 files changed, 1214 insertions(+), 3 deletions(-) create mode 100644 Pipedrive/Pipedrive_Get_a_note.ipynb create mode 100644 Pipedrive/Pipedrive_Get_all_notes.ipynb create mode 100644 Pipedrive/Pipedrive_Update_a_deal.ipynb create mode 100644 Pipedrive/Pipedrive_Update_a_note.ipynb diff --git a/Pipedrive/Pipedrive_Get_a_note.ipynb b/Pipedrive/Pipedrive_Get_a_note.ipynb new file mode 100644 index 0000000000..048ceb65ba --- /dev/null +++ b/Pipedrive/Pipedrive_Get_a_note.ipynb @@ -0,0 +1,291 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "71c0bc07-d10e-4777-9d07-f8069593b9dc", + "metadata": { + "papermill": {}, + "tags": [ + "naas" + ] + }, + "source": [ + "\"Pipedrive.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "c2297c6c-1c56-44f5-ab1b-4f358315ae4d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Pipedrive - Get details of a note\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "1528c23e-d4b5-4dae-aedd-3e0c3de7a07e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #pipedrive #note #get #snippet #api #v1 #python" + ] + }, + { + "cell_type": "markdown", + "id": "0f5b4999-cf8f-429b-a3b5-60abd6f0b4cb", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "b50cf866-b0f5-45c1-9ea2-4c63d5622675", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-01-04 (Created: 2023-01-04)" + ] + }, + { + "cell_type": "markdown", + "id": "da21ae20-d8f3-41ae-b6e4-1d16e8bca2d0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook returns the details of a note." + ] + }, + { + "cell_type": "markdown", + "id": "6a0004b2-eb12-4dc2-b721-6b482cab7439", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Pipedrive API v1 Documentation](https://developers.pipedrive.com/docs/api/v1/Notes#getNote)\n", + "- [Pipedrive API Authentication](https://developers.pipedrive.com/docs/api/authentication)\n", + "- [Get your Pipedrive API token](https://developers.pipedrive.com/docs/api/authentication)." + ] + }, + { + "cell_type": "markdown", + "id": "906e7461-ec7c-4efe-952b-79a2fcdf2b94", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "699c6ed8-1d1c-4712-b64c-34ed8b385130", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "771e3ddd-f295-4b44-a7d5-0873ee5be72a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import naas" + ] + }, + { + "cell_type": "markdown", + "id": "0ab0d130-cbec-438c-a188-8a0cb295da4e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "- `api_token`: API token used to authenticate the request.\n", + "- `object_id`: ID of the note." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6ffb591-6b88-43f6-95b7-a93de4040366", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_token = naas.secret.get(\"PIPEDRIVE_API_KEY\") or \"YOUR_API_TOKEN\"\n", + "object_id = 3637" + ] + }, + { + "cell_type": "markdown", + "id": "61a6835b-4526-4d1e-9e21-e2c9325f0206", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "35bdc814-3909-4188-94c0-0c1faf996c1e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get a note" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6810b2b3-de2c-4929-b2ff-f5d9c176ddbd", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def get_note(api_token, object_id):\n", + " api_url = f'https://api.pipedrive.com/v1/notes/{object_id}?api_token={api_token}'\n", + " res = requests.get(api_url)\n", + " res.raise_for_status()\n", + " if res.status_code == 200:\n", + " return res.json()\n", + " else:\n", + " print(f'Failed to get organization with id {object_id}. Status code: {res.status_code}')\n", + " \n", + "result = get_note(api_token, object_id)\n", + "print(\"Note ID:\", result.get('data').get(\"id\"))\n", + "print(\"Note content:\", result.get('data').get(\"content\"))" + ] + }, + { + "cell_type": "markdown", + "id": "7c89f6ac-4231-46ea-81ba-3aa90bc46f3c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "ca89baa8-b76c-4f9e-8d60-74fdfacf141d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e6814d5-bfeb-413a-a4e9-7d9c70c4d95b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "result.get(\"data\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e26c07fc-63e7-475f-b4d6-91a4096f6bfc", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "5e625e87-9a42-44a4-a872-9ab557638886", + "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" + }, + "naas": { + "notebook_id": "ac0a2a8f823eaaec488085cbf985de5cceb467ba42d8856876fe0ecbcee2706a", + "notebook_path": "Pipedrive/Pipedrive_Get_a_person.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.5.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Pipedrive/Pipedrive_Get_all_notes.ipynb b/Pipedrive/Pipedrive_Get_all_notes.ipynb new file mode 100644 index 0000000000..c1898aedae --- /dev/null +++ b/Pipedrive/Pipedrive_Get_all_notes.ipynb @@ -0,0 +1,332 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "71c0bc07-d10e-4777-9d07-f8069593b9dc", + "metadata": { + "papermill": {}, + "tags": [ + "naas" + ] + }, + "source": [ + "\"Pipedrive.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "c2297c6c-1c56-44f5-ab1b-4f358315ae4d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Pipedrive - Get all notes\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "1528c23e-d4b5-4dae-aedd-3e0c3de7a07e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #pipedrive #notes #get #snippet #api #v1 #python #csv #export" + ] + }, + { + "cell_type": "markdown", + "id": "0f5b4999-cf8f-429b-a3b5-60abd6f0b4cb", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "b50cf866-b0f5-45c1-9ea2-4c63d5622675", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-01-04 (Created: 2023-01-04)" + ] + }, + { + "cell_type": "markdown", + "id": "da21ae20-d8f3-41ae-b6e4-1d16e8bca2d0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook retrieves all notes with access to your Pipedrive account." + ] + }, + { + "cell_type": "markdown", + "id": "6a0004b2-eb12-4dc2-b721-6b482cab7439", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Pipedrive API v1 Documentation](https://developers.pipedrive.com/docs/api/v1/Notes#getNotes)\n", + "- [Pipedrive API Authentication](https://developers.pipedrive.com/docs/api/authentication)\n", + "- [Get your Pipedrive API token](https://developers.pipedrive.com/docs/api/authentication)." + ] + }, + { + "cell_type": "markdown", + "id": "906e7461-ec7c-4efe-952b-79a2fcdf2b94", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "699c6ed8-1d1c-4712-b64c-34ed8b385130", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "771e3ddd-f295-4b44-a7d5-0873ee5be72a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import naas\n", + "import pandas as pd\n", + "from datetime import date" + ] + }, + { + "cell_type": "markdown", + "id": "0ab0d130-cbec-438c-a188-8a0cb295da4e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "- `api_token`: API token used to authenticate the request.\n", + "- `file_path`: CSV file path to save data\n", + "- `params`: query parameters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6ffb591-6b88-43f6-95b7-a93de4040366", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_token = naas.secret.get(\"PIPEDRIVE_API_KEY\") or \"YOUR_API_TOKEN\"\n", + "file_path = f\"{date.today().isoformat()}_export_pipedrive_notes.csv\"\n", + "params = {\n", + " \"user_id\": None,\n", + " \"lead_id\": None,\n", + " \"deal_id\": None,\n", + " \"person_id\": None,\n", + " \"org_id\": None,\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "61a6835b-4526-4d1e-9e21-e2c9325f0206", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "35bdc814-3909-4188-94c0-0c1faf996c1e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get all notes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6810b2b3-de2c-4929-b2ff-f5d9c176ddbd", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Flatten the nested dict\n", + "def flatten_dict(d, parent_key='', sep='_'):\n", + " \"\"\"\n", + " Flattens a nested dictionary into a single level dictionary.\n", + "\n", + " Args:\n", + " d (dict): A nested dictionary.\n", + " parent_key (str): Optional string to prefix the keys with.\n", + " sep (str): Optional separator to use between parent_key and child_key.\n", + "\n", + " Returns:\n", + " dict: A flattened dictionary.\n", + " \"\"\"\n", + " items = []\n", + " for k, v in d.items():\n", + " new_key = f\"{parent_key}{sep}{k}\" if parent_key else k\n", + " if isinstance(v, dict):\n", + " items.extend(flatten_dict(v, new_key, sep=sep).items())\n", + " else:\n", + " items.append((new_key, v))\n", + " return dict(items)\n", + "\n", + "def get_all_notes(\n", + " api_token,\n", + " params,\n", + " start=0,\n", + " limit=100,\n", + "):\n", + " # Init\n", + " data = []\n", + " \n", + " # Requests\n", + " while True:\n", + " api_url = f'https://api.pipedrive.com/v1/notes?api_token={api_token}&start={start}&limit={limit}'\n", + " res = requests.get(api_url, params)\n", + " res.raise_for_status()\n", + " if res.status_code == 200:\n", + " res_json = res.json()\n", + " else:\n", + " print(f'Failed to get all notes. Status code: {res.status_code}')\n", + " break\n", + " \n", + " # Clean data\n", + " if res_json.get(\"success\") and res_json.get('data') is not None:\n", + " for r in res_json.get('data'):\n", + " data.append(flatten_dict(r))\n", + " start += 100\n", + " else:\n", + " break\n", + " return pd.DataFrame(data)\n", + " \n", + "df = get_all_notes(api_token, params)\n", + "print(\"Notes:\", len(df))\n", + "df.head(5)" + ] + }, + { + "cell_type": "markdown", + "id": "7c89f6ac-4231-46ea-81ba-3aa90bc46f3c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "ca89baa8-b76c-4f9e-8d60-74fdfacf141d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Save data to CSV" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e6814d5-bfeb-413a-a4e9-7d9c70c4d95b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "df.to_csv(file_path, index=False)" + ] + }, + { + "cell_type": "markdown", + "id": "5e625e87-9a42-44a4-a872-9ab557638886", + "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" + }, + "naas": { + "notebook_id": "b4812eff96c87d4b997726222b46c78185091db414e792a1f643a595b40429c4", + "notebook_path": "Pipedrive/Pipedrive_Get_all_users.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.5.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Pipedrive/Pipedrive_Update_a_deal.ipynb b/Pipedrive/Pipedrive_Update_a_deal.ipynb new file mode 100644 index 0000000000..5b51f6f247 --- /dev/null +++ b/Pipedrive/Pipedrive_Update_a_deal.ipynb @@ -0,0 +1,296 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "71c0bc07-d10e-4777-9d07-f8069593b9dc", + "metadata": { + "papermill": {}, + "tags": [ + "naas" + ] + }, + "source": [ + "\"Pipedrive.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "c2297c6c-1c56-44f5-ab1b-4f358315ae4d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Pipedrive - Update a deal\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "1528c23e-d4b5-4dae-aedd-3e0c3de7a07e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #pipedrive #deal #update #snippet #api #v1 #python" + ] + }, + { + "cell_type": "markdown", + "id": "0f5b4999-cf8f-429b-a3b5-60abd6f0b4cb", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "b50cf866-b0f5-45c1-9ea2-4c63d5622675", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-01-04 (Created: 2023-01-04)" + ] + }, + { + "cell_type": "markdown", + "id": "da21ae20-d8f3-41ae-b6e4-1d16e8bca2d0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook updates the properties of a deal." + ] + }, + { + "cell_type": "markdown", + "id": "6a0004b2-eb12-4dc2-b721-6b482cab7439", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Pipedrive API v1 Documentation](https://developers.pipedrive.com/docs/api/v1/Deals#updateDeal)\n", + "- [Pipedrive API Authentication](https://developers.pipedrive.com/docs/api/authentication)\n", + "- [Get your Pipedrive API token](https://developers.pipedrive.com/docs/api/authentication)." + ] + }, + { + "cell_type": "markdown", + "id": "906e7461-ec7c-4efe-952b-79a2fcdf2b94", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "699c6ed8-1d1c-4712-b64c-34ed8b385130", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "771e3ddd-f295-4b44-a7d5-0873ee5be72a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import naas" + ] + }, + { + "cell_type": "markdown", + "id": "0ab0d130-cbec-438c-a188-8a0cb295da4e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "- `api_token`: API token used to authenticate the request.\n", + "- `object_id`: ID of the deal to be updated.\n", + "- `data`: Dict of Pipedrive object key and value" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6ffb591-6b88-43f6-95b7-a93de4040366", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_token = naas.secret.get(\"PIPEDRIVE_API_KEY\") or \"YOUR_API_TOKEN\"\n", + "object_id = 100838\n", + "data = {\n", + " \"title\": \"Test\",\n", + " \"value\": 0,\n", + " \"user_id\": 13470003,\n", + " \"person_id\": 100838,\n", + " \"org_id\": 3363,\n", + " \"pipeline_id\": 14,\n", + " \"stage_id\": 95,\n", + " \"status\": \"open\",\n", + " \"probability\": 10,\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "61a6835b-4526-4d1e-9e21-e2c9325f0206", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "597d4838-f2c9-49d8-bdb0-c37fee74e485", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Update deal" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7cc14a2-049c-44ee-b9f9-8bea1f58c306", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def update_deal(api_token, object_id, data):\n", + " api_url = f'https://api.pipedrive.com/v1/deals/{object_id}'\n", + " params = {\n", + " \"api_token\": api_token,\n", + " }\n", + " res = requests.put(api_url, params=params, json=data)\n", + " res.raise_for_status()\n", + " if res.status_code == 200:\n", + " return res.json()\n", + " else:\n", + " print(f'Failed to get deal with id {object_id}. Status code: {res.status_code}')\n", + " \n", + "result = update_deal(api_token, object_id, data)\n", + "for d in data:\n", + " update = result.get(\"data\").get(d)\n", + " print(f\"- Updated field {d}:\", update)" + ] + }, + { + "cell_type": "markdown", + "id": "7c89f6ac-4231-46ea-81ba-3aa90bc46f3c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "ca89baa8-b76c-4f9e-8d60-74fdfacf141d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e6814d5-bfeb-413a-a4e9-7d9c70c4d95b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "result.get('data')" + ] + }, + { + "cell_type": "markdown", + "id": "5e625e87-9a42-44a4-a872-9ab557638886", + "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" + }, + "naas": { + "notebook_id": "e495ee5783b582fd158948b12eff6ede20bf753f8ae35710e835819fd8eb96c4", + "notebook_path": "Pipedrive/Pipedrive_Update_a_person.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.5.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Pipedrive/Pipedrive_Update_a_note.ipynb b/Pipedrive/Pipedrive_Update_a_note.ipynb new file mode 100644 index 0000000000..25daf6b381 --- /dev/null +++ b/Pipedrive/Pipedrive_Update_a_note.ipynb @@ -0,0 +1,292 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "71c0bc07-d10e-4777-9d07-f8069593b9dc", + "metadata": { + "papermill": {}, + "tags": [ + "naas" + ] + }, + "source": [ + "\"Pipedrive.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "c2297c6c-1c56-44f5-ab1b-4f358315ae4d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Pipedrive - Update a note\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "1528c23e-d4b5-4dae-aedd-3e0c3de7a07e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #pipedrive #note #update #snippet #api #v1 #python" + ] + }, + { + "cell_type": "markdown", + "id": "0f5b4999-cf8f-429b-a3b5-60abd6f0b4cb", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "b50cf866-b0f5-45c1-9ea2-4c63d5622675", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-01-04 (Created: 2023-01-04)" + ] + }, + { + "cell_type": "markdown", + "id": "da21ae20-d8f3-41ae-b6e4-1d16e8bca2d0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook updates the properties of a note." + ] + }, + { + "cell_type": "markdown", + "id": "6a0004b2-eb12-4dc2-b721-6b482cab7439", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n", + "- [Pipedrive API v1 Documentation](https://developers.pipedrive.com/docs/api/v1/Notes#updateNote)\n", + "- [Pipedrive API Authentication](https://developers.pipedrive.com/docs/api/authentication)\n", + "- [Get your Pipedrive API token](https://developers.pipedrive.com/docs/api/authentication)." + ] + }, + { + "cell_type": "markdown", + "id": "906e7461-ec7c-4efe-952b-79a2fcdf2b94", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "699c6ed8-1d1c-4712-b64c-34ed8b385130", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "771e3ddd-f295-4b44-a7d5-0873ee5be72a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import naas" + ] + }, + { + "cell_type": "markdown", + "id": "0ab0d130-cbec-438c-a188-8a0cb295da4e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "- `api_token`: API token used to authenticate the request.\n", + "- `object_id`: ID of the note to be updated.\n", + "- `data`: Dict of Pipedrive object key and value" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6ffb591-6b88-43f6-95b7-a93de4040366", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_token = naas.secret.get(\"PIPEDRIVE_API_KEY\") or \"YOUR_API_TOKEN\"\n", + "object_id = 100838\n", + "data = {\n", + " \"content\": \"My first note\",\n", + " \"deal_id\": 2454,\n", + " \"user_id\": 13470003,\n", + " \"person_id\": 100838,\n", + " \"org_id\": 3363,\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "61a6835b-4526-4d1e-9e21-e2c9325f0206", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "597d4838-f2c9-49d8-bdb0-c37fee74e485", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Update note" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7cc14a2-049c-44ee-b9f9-8bea1f58c306", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def update_note(api_token, object_id, data):\n", + " api_url = f'https://api.pipedrive.com/v1/notes/{object_id}'\n", + " params = {\n", + " \"api_token\": api_token,\n", + " }\n", + " res = requests.put(api_url, params=params, json=data)\n", + " res.raise_for_status()\n", + " if res.status_code == 200:\n", + " return res.json()\n", + " else:\n", + " print(f'Failed to get note with id {object_id}. Status code: {res.status_code}')\n", + " \n", + "result = update_note(api_token, object_id, data)\n", + "for d in data:\n", + " update = result.get(\"data\").get(d)\n", + " print(f\"- Updated field {d}:\", update)" + ] + }, + { + "cell_type": "markdown", + "id": "7c89f6ac-4231-46ea-81ba-3aa90bc46f3c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "ca89baa8-b76c-4f9e-8d60-74fdfacf141d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e6814d5-bfeb-413a-a4e9-7d9c70c4d95b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "result.get('data')" + ] + }, + { + "cell_type": "markdown", + "id": "5e625e87-9a42-44a4-a872-9ab557638886", + "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" + }, + "naas": { + "notebook_id": "e495ee5783b582fd158948b12eff6ede20bf753f8ae35710e835819fd8eb96c4", + "notebook_path": "Pipedrive/Pipedrive_Update_a_person.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.5.0" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Pipedrive/Pipedrive_Update_a_person.ipynb b/Pipedrive/Pipedrive_Update_a_person.ipynb index b812fd1834..a2811b8f78 100644 --- a/Pipedrive/Pipedrive_Update_a_person.ipynb +++ b/Pipedrive/Pipedrive_Update_a_person.ipynb @@ -21,7 +21,7 @@ "tags": [] }, "source": [ - "# Pipedrive - Update an person\n", + "# Pipedrive - Update a person\n", "

Give Feedback | Bug report" ] }, @@ -66,7 +66,7 @@ "tags": [] }, "source": [ - "**Description:** This notebook updates the properties of an person." + "**Description:** This notebook updates the properties of a person." ] }, { @@ -288,4 +288,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +}