diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8b03474bb6..89b40a362d 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,9 +1,5 @@ ## Fixes - This PR resolves #issue_number ## What does this PR do? -(Provide a description of what this PR does and why it's needed.) - -## Screenshots Provide supporting docs, limitations if any, video of the template, or anything that you want to share to support your PR diff --git a/SendGrid/SendGrid_Add_or_Update_Contacts.ipynb b/SendGrid/SendGrid_Add_or_Update_Contacts.ipynb new file mode 100644 index 0000000000..46da6044ca --- /dev/null +++ b/SendGrid/SendGrid_Add_or_Update_Contacts.ipynb @@ -0,0 +1,305 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "85db721e-2267-40ca-ac5b-00c08ec10ff0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"SendGrid.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "2ba2f665-d276-4881-81f8-c9524f75796b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# SendGrid - Add or Update Contacts" + ] + }, + { + "cell_type": "markdown", + "id": "b55448ec-bd35-4884-b72f-a06a3f12c914", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #sendgrid #snippet #operations #dataframe #contacts #add #update" + ] + }, + { + "cell_type": "markdown", + "id": "b025116f-fd57-40ae-81db-99d9dbc30445", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "70c1e871-3abb-4b63-9540-fb7a7138486e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2024-08-02 (Created: 2024-08-02)" + ] + }, + { + "cell_type": "markdown", + "id": "naas-description", + "metadata": { + "papermill": {}, + "tags": [ + "description" + ] + }, + "source": [ + "**Description:** This notebook add or update contacts in SendGrid." + ] + }, + { + "cell_type": "markdown", + "id": "ec2132f6-bf89-4236-8ac7-0c207f8f03b1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "81f26c9b-0c3c-4cf8-ad50-dc67e6329ba1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "26c428b4-66f4-48a4-82db-ff24cdec1782", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:40:10.847920Z", + "iopub.status.busy": "2024-08-02T15:40:10.847478Z", + "iopub.status.idle": "2024-08-02T15:40:10.949533Z", + "shell.execute_reply": "2024-08-02T15:40:10.948928Z", + "shell.execute_reply.started": "2024-08-02T15:40:10.847832Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests" + ] + }, + { + "cell_type": "markdown", + "id": "392e708f-7c32-45d7-8937-382c9651fc0f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "2de7b1bc-5ec9-4fa7-b89f-3f72f1b9a5e0", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:40:10.951151Z", + "iopub.status.busy": "2024-08-02T15:40:10.950884Z", + "iopub.status.idle": "2024-08-02T15:40:10.976974Z", + "shell.execute_reply": "2024-08-02T15:40:10.976430Z", + "shell.execute_reply.started": "2024-08-02T15:40:10.951089Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_key = \"SG.xxxxxxxxxxxxxxxxx\"\n", + "contacts = [\n", + " {\n", + " \"email\": \"example1@gmail.com\",\n", + " \"first_name\": \"John\",\n", + " \"last_name\": \"Doe\"\n", + " },\n", + " {\n", + " \"email\": \"example2@gmail.com\",\n", + " \"first_name\": \"Jane\",\n", + " \"last_name\": \"Doe\"\n", + " }\n", + "]\n", + "list_ids = []" + ] + }, + { + "cell_type": "markdown", + "id": "a180347f-a2e1-44b2-bce0-775c7ac63b04", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "61983024-d97c-46d5-b27c-b7d5c7af5869", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Add or Update Contacts" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "b5d42846-8db8-4bba-b6c6-d37af7b1c138", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:40:10.978302Z", + "iopub.status.busy": "2024-08-02T15:40:10.978067Z", + "iopub.status.idle": "2024-08-02T15:40:11.830979Z", + "shell.execute_reply": "2024-08-02T15:40:11.830299Z", + "shell.execute_reply.started": "2024-08-02T15:40:10.978272Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'job_id': '6dd4fd64-d82c-4441-b5c7-4b7f6f15d63c'}\n" + ] + } + ], + "source": [ + "def create_contacts(api_key, contacts, list_ids):\n", + " headers = {\n", + " \"Authorization\": \"Bearer \" + api_key,\n", + " \"Content-Type\": \"application/json\"\n", + " }\n", + " data = {\n", + " \"list_ids\": list_ids,\n", + " \"contacts\": contacts\n", + " }\n", + " response = requests.put('https://api.sendgrid.com/v3/marketing/contacts', headers=headers, json=data)\n", + " return response.json()\n", + "\n", + "results = create_contacts(api_key, contacts, list_ids)\n", + "print(results)" + ] + }, + { + "cell_type": "markdown", + "id": "6109e162-ea7e-4db3-bb71-41c5e1403ea1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "b54a2952-c67e-418b-b491-40162fb75477", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "7a3247b7-a627-41b0-89e9-2b7c39b0be47", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:40:11.832064Z", + "iopub.status.busy": "2024-08-02T15:40:11.831893Z", + "iopub.status.idle": "2024-08-02T15:40:11.842147Z", + "shell.execute_reply": "2024-08-02T15:40:11.841515Z", + "shell.execute_reply.started": "2024-08-02T15:40:11.832044Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'job_id': '6dd4fd64-d82c-4441-b5c7-4b7f6f15d63c'}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results" + ] + } + ], + "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": "d7e34a46dfdab62d55033522183e338b4bfd89523400494c9c14a7880471b1cb", + "notebook_path": "SendGrid/SendGrid_Get_all_messages.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/SendGrid/SendGrid_Get_Contacts.ipynb b/SendGrid/SendGrid_Get_Contacts.ipynb new file mode 100644 index 0000000000..0e155250c5 --- /dev/null +++ b/SendGrid/SendGrid_Get_Contacts.ipynb @@ -0,0 +1,260 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "85db721e-2267-40ca-ac5b-00c08ec10ff0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"SendGrid.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "2ba2f665-d276-4881-81f8-c9524f75796b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# SendGrid - Get Contacts" + ] + }, + { + "cell_type": "markdown", + "id": "b55448ec-bd35-4884-b72f-a06a3f12c914", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #sendgrid #snippet #operations #dataframe #contacts" + ] + }, + { + "cell_type": "markdown", + "id": "b025116f-fd57-40ae-81db-99d9dbc30445", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "70c1e871-3abb-4b63-9540-fb7a7138486e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2024-08-02 (Created: 2024-08-02)" + ] + }, + { + "cell_type": "markdown", + "id": "naas-description", + "metadata": { + "papermill": {}, + "tags": [ + "description" + ] + }, + "source": [ + "**Description:** This notebook get contacts from SendGrid." + ] + }, + { + "cell_type": "markdown", + "id": "ec2132f6-bf89-4236-8ac7-0c207f8f03b1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "81f26c9b-0c3c-4cf8-ad50-dc67e6329ba1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26c428b4-66f4-48a4-82db-ff24cdec1782", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "392e708f-7c32-45d7-8937-382c9651fc0f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2de7b1bc-5ec9-4fa7-b89f-3f72f1b9a5e0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_key = \"SG.xxxxxxxxxxxxxxxxx\"" + ] + }, + { + "cell_type": "markdown", + "id": "a180347f-a2e1-44b2-bce0-775c7ac63b04", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "61983024-d97c-46d5-b27c-b7d5c7af5869", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get contacts" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b5d42846-8db8-4bba-b6c6-d37af7b1c138", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def get_all_contacts(api_key):\n", + " headers = {\n", + " \"Authorization\": \"Bearer \" + api_key\n", + " }\n", + " \n", + " # Initialize page to 1\n", + " page = 1\n", + " all_contacts = []\n", + " page_size = 1000\n", + " while True:\n", + " response = requests.get(f'https://api.sendgrid.com/v3/marketing/contacts?page_size={page_size}&page_token={page}', headers=headers)\n", + " data = response.json()\n", + " contact_count = data.get(\"contact_count\")\n", + " \n", + " # Add the contacts from the current page to the list\n", + " all_contacts.extend(data['result'])\n", + " \n", + " # Increment the page number for the next iteration\n", + " if contact_count <= page_size:\n", + " break\n", + " elif len(all_contacts) >= contact_count:\n", + " break\n", + " page += 1\n", + " \n", + " return all_contacts\n", + "\n", + "results = get_all_contacts(api_key)\n", + "print(results)" + ] + }, + { + "cell_type": "markdown", + "id": "6109e162-ea7e-4db3-bb71-41c5e1403ea1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "b54a2952-c67e-418b-b491-40162fb75477", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a3247b7-a627-41b0-89e9-2b7c39b0be47", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "pd.DataFrame(results)" + ] + } + ], + "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": "d7e34a46dfdab62d55033522183e338b4bfd89523400494c9c14a7880471b1cb", + "notebook_path": "SendGrid/SendGrid_Get_all_messages.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/SendGrid/SendGrid_Get_Lists.ipynb b/SendGrid/SendGrid_Get_Lists.ipynb new file mode 100644 index 0000000000..c93d395f2a --- /dev/null +++ b/SendGrid/SendGrid_Get_Lists.ipynb @@ -0,0 +1,294 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "85db721e-2267-40ca-ac5b-00c08ec10ff0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"SendGrid.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "2ba2f665-d276-4881-81f8-c9524f75796b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# SendGrid - Get Lists" + ] + }, + { + "cell_type": "markdown", + "id": "b55448ec-bd35-4884-b72f-a06a3f12c914", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #sendgrid #snippet #operations #dataframe #lists" + ] + }, + { + "cell_type": "markdown", + "id": "b025116f-fd57-40ae-81db-99d9dbc30445", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "70c1e871-3abb-4b63-9540-fb7a7138486e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2024-08-02 (Created: 2024-08-02)" + ] + }, + { + "cell_type": "markdown", + "id": "naas-description", + "metadata": { + "papermill": {}, + "tags": [ + "description" + ] + }, + "source": [ + "**Description:** This notebook get lists from SendGrid." + ] + }, + { + "cell_type": "markdown", + "id": "ec2132f6-bf89-4236-8ac7-0c207f8f03b1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "81f26c9b-0c3c-4cf8-ad50-dc67e6329ba1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "26c428b4-66f4-48a4-82db-ff24cdec1782", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:40:42.116209Z", + "iopub.status.busy": "2024-08-02T15:40:42.116013Z", + "iopub.status.idle": "2024-08-02T15:40:42.216352Z", + "shell.execute_reply": "2024-08-02T15:40:42.215588Z", + "shell.execute_reply.started": "2024-08-02T15:40:42.116162Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests" + ] + }, + { + "cell_type": "markdown", + "id": "392e708f-7c32-45d7-8937-382c9651fc0f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "2de7b1bc-5ec9-4fa7-b89f-3f72f1b9a5e0", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:40:42.218093Z", + "iopub.status.busy": "2024-08-02T15:40:42.217618Z", + "iopub.status.idle": "2024-08-02T15:40:42.235392Z", + "shell.execute_reply": "2024-08-02T15:40:42.234865Z", + "shell.execute_reply.started": "2024-08-02T15:40:42.218060Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_key = \"SG.xxxxxxxxxxxxxxxxx\"" + ] + }, + { + "cell_type": "markdown", + "id": "a180347f-a2e1-44b2-bce0-775c7ac63b04", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "61983024-d97c-46d5-b27c-b7d5c7af5869", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get all lists from Sendgrid" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "b5d42846-8db8-4bba-b6c6-d37af7b1c138", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:40:42.236507Z", + "iopub.status.busy": "2024-08-02T15:40:42.236285Z", + "iopub.status.idle": "2024-08-02T15:40:42.901666Z", + "shell.execute_reply": "2024-08-02T15:40:42.901030Z", + "shell.execute_reply.started": "2024-08-02T15:40:42.236477Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'result': [{'name': 'Naas Workspace', 'id': 'af26c293-cece-4768-b32b-be630bfdffa5', 'contact_count': 0, '_metadata': {'self': 'https://api.sendgrid.com/v3/marketing/lists/af26c293-cece-4768-b32b-be630bfdffa5'}}, {'name': 'Lab Users', 'id': 'f16beff7-8a18-4456-853c-b7cdecfee593', 'contact_count': 0, '_metadata': {'self': 'https://api.sendgrid.com/v3/marketing/lists/f16beff7-8a18-4456-853c-b7cdecfee593'}}], '_metadata': {'self': 'https://api.sendgrid.com/v3/marketing/lists?page_size=100&page_token=', 'count': 3}}\n" + ] + } + ], + "source": [ + "def get_all_lists(api_key):\n", + " headers = {\n", + " \"Authorization\": \"Bearer \" + api_key\n", + " }\n", + " response = requests.get('https://api.sendgrid.com/v3/marketing/lists', headers=headers)\n", + " return response.json()\n", + "\n", + "results = get_all_lists(api_key)\n", + "print(results)" + ] + }, + { + "cell_type": "markdown", + "id": "6109e162-ea7e-4db3-bb71-41c5e1403ea1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "b54a2952-c67e-418b-b491-40162fb75477", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "7a3247b7-a627-41b0-89e9-2b7c39b0be47", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:40:42.902687Z", + "iopub.status.busy": "2024-08-02T15:40:42.902469Z", + "iopub.status.idle": "2024-08-02T15:40:42.914828Z", + "shell.execute_reply": "2024-08-02T15:40:42.914262Z", + "shell.execute_reply.started": "2024-08-02T15:40:42.902652Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'name': 'Naas Workspace',\n", + " 'id': 'af26c293-cece-4768-b32b-be630bfdffa5',\n", + " 'contact_count': 0,\n", + " '_metadata': {'self': 'https://api.sendgrid.com/v3/marketing/lists/af26c293-cece-4768-b32b-be630bfdffa5'}},\n", + " {'name': 'Lab Users',\n", + " 'id': 'f16beff7-8a18-4456-853c-b7cdecfee593',\n", + " 'contact_count': 0,\n", + " '_metadata': {'self': 'https://api.sendgrid.com/v3/marketing/lists/f16beff7-8a18-4456-853c-b7cdecfee593'}}]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results.get(\"result\")" + ] + } + ], + "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": "d7e34a46dfdab62d55033522183e338b4bfd89523400494c9c14a7880471b1cb", + "notebook_path": "SendGrid/SendGrid_Get_all_messages.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/SendGrid/SendGrid_Get_Single_Sends.ipynb b/SendGrid/SendGrid_Get_Single_Sends.ipynb new file mode 100644 index 0000000000..b13152fddc --- /dev/null +++ b/SendGrid/SendGrid_Get_Single_Sends.ipynb @@ -0,0 +1,366 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "85db721e-2267-40ca-ac5b-00c08ec10ff0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"SendGrid.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "2ba2f665-d276-4881-81f8-c9524f75796b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# SendGrid - Get Single Sends" + ] + }, + { + "cell_type": "markdown", + "id": "b55448ec-bd35-4884-b72f-a06a3f12c914", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #sendgrid #snippet #operations #dataframe #singlesends" + ] + }, + { + "cell_type": "markdown", + "id": "b025116f-fd57-40ae-81db-99d9dbc30445", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "70c1e871-3abb-4b63-9540-fb7a7138486e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2024-08-02 (Created: 2024-08-02)" + ] + }, + { + "cell_type": "markdown", + "id": "naas-description", + "metadata": { + "papermill": {}, + "tags": [ + "description" + ] + }, + "source": [ + "**Description:** This notebook get singlesends from SendGrid." + ] + }, + { + "cell_type": "markdown", + "id": "ec2132f6-bf89-4236-8ac7-0c207f8f03b1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "81f26c9b-0c3c-4cf8-ad50-dc67e6329ba1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "26c428b4-66f4-48a4-82db-ff24cdec1782", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:29:04.713910Z", + "iopub.status.busy": "2024-08-02T15:29:04.713472Z", + "iopub.status.idle": "2024-08-02T15:29:06.616746Z", + "shell.execute_reply": "2024-08-02T15:29:06.616111Z", + "shell.execute_reply.started": "2024-08-02T15:29:04.713842Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "392e708f-7c32-45d7-8937-382c9651fc0f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "2de7b1bc-5ec9-4fa7-b89f-3f72f1b9a5e0", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:29:06.619627Z", + "iopub.status.busy": "2024-08-02T15:29:06.619428Z", + "iopub.status.idle": "2024-08-02T15:29:06.623928Z", + "shell.execute_reply": "2024-08-02T15:29:06.623341Z", + "shell.execute_reply.started": "2024-08-02T15:29:06.619606Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_key = \"SG.xxxxxxxxxxxxxxxxx\"" + ] + }, + { + "cell_type": "markdown", + "id": "a180347f-a2e1-44b2-bce0-775c7ac63b04", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "61983024-d97c-46d5-b27c-b7d5c7af5869", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get Single Sends" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b5d42846-8db8-4bba-b6c6-d37af7b1c138", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:29:37.272445Z", + "iopub.status.busy": "2024-08-02T15:29:37.272211Z", + "iopub.status.idle": "2024-08-02T15:29:37.726368Z", + "shell.execute_reply": "2024-08-02T15:29:37.725746Z", + "shell.execute_reply.started": "2024-08-02T15:29:37.272421Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Single Sends: 8\n" + ] + } + ], + "source": [ + "def get_single_sends(api_key):\n", + " headers = {\n", + " \"Authorization\": \"Bearer \" + api_key\n", + " }\n", + " response = requests.get('https://api.sendgrid.com/v3/marketing/singlesends', headers=headers)\n", + " return response.json()\n", + "\n", + "results = get_single_sends(api_key)\n", + "if len(results) > 0:\n", + " print(\"Single Sends:\", len(results.get(\"result\")))" + ] + }, + { + "cell_type": "markdown", + "id": "6109e162-ea7e-4db3-bb71-41c5e1403ea1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "b54a2952-c67e-418b-b491-40162fb75477", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "7a3247b7-a627-41b0-89e9-2b7c39b0be47", + "metadata": { + "execution": { + "iopub.execute_input": "2024-08-02T15:29:47.492426Z", + "iopub.status.busy": "2024-08-02T15:29:47.492191Z", + "iopub.status.idle": "2024-08-02T15:29:47.498133Z", + "shell.execute_reply": "2024-08-02T15:29:47.497503Z", + "shell.execute_reply.started": "2024-08-02T15:29:47.492402Z" + }, + "papermill": {}, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'id': '8958cf52-500d-11ef-84ad-d2f8fe674118',\n", + " 'name': 'Untitled Single Send',\n", + " 'status': 'draft',\n", + " 'categories': [],\n", + " 'send_at': None,\n", + " 'created_at': '2024-08-01T13:54:14Z',\n", + " 'updated_at': '2024-08-01T15:32:52Z',\n", + " 'is_abtest': True,\n", + " 'abtest': {'type': '',\n", + " 'winner_criteria': '',\n", + " 'test_percentage': 0,\n", + " 'duration': '',\n", + " 'winning_template_id': '',\n", + " 'winner_selected_at': None,\n", + " 'expiration_date': None}},\n", + " {'id': '7dddde73-500d-11ef-a102-364a19add505',\n", + " 'name': 'Untitled Single Send',\n", + " 'status': 'draft',\n", + " 'categories': [],\n", + " 'send_at': None,\n", + " 'created_at': '2024-08-01T13:53:55Z',\n", + " 'updated_at': '2024-08-01T13:54:30Z',\n", + " 'is_abtest': False,\n", + " 'abtest': None},\n", + " {'id': 'a1f26dfa-3e03-11ef-8093-8ec483586f18',\n", + " 'name': 'Important Update: New Access Model and Features for Naas Services',\n", + " 'status': 'triggered',\n", + " 'categories': [],\n", + " 'send_at': '2024-07-09T15:35:20Z',\n", + " 'created_at': '2024-07-09T14:58:00Z',\n", + " 'updated_at': '2024-07-09T15:36:08Z',\n", + " 'is_abtest': False,\n", + " 'abtest': None},\n", + " {'id': 'c09afe6e-eb7f-11ea-b7f6-02c61b809719',\n", + " 'name': '📜 Bienvenue dans CashStory « Education »',\n", + " 'status': 'draft',\n", + " 'categories': [],\n", + " 'send_at': None,\n", + " 'created_at': '2020-08-31T11:47:31Z',\n", + " 'updated_at': '2020-10-07T19:21:23Z',\n", + " 'is_abtest': False,\n", + " 'abtest': None},\n", + " {'id': 'fabef78e-8acf-11ea-8420-9abd1bb76ba1',\n", + " 'name': 'Newsletter 04/30',\n", + " 'status': 'triggered',\n", + " 'categories': [],\n", + " 'send_at': '2020-04-30T12:11:28Z',\n", + " 'created_at': '2020-04-30T10:47:26Z',\n", + " 'updated_at': '2020-04-30T12:12:08Z',\n", + " 'is_abtest': False,\n", + " 'abtest': None},\n", + " {'id': '8ce63e6e-8581-11ea-b766-2e577282b43b',\n", + " 'name': 'Communiqué de presse 2',\n", + " 'status': 'triggered',\n", + " 'categories': [],\n", + " 'send_at': '2020-04-24T06:04:57Z',\n", + " 'created_at': '2020-04-23T16:43:25Z',\n", + " 'updated_at': '2020-04-24T06:05:09Z',\n", + " 'is_abtest': False,\n", + " 'abtest': None},\n", + " {'id': '5d34bbcb-8582-11ea-9717-0a54bbc3326b',\n", + " 'name': 'Newsletter 2',\n", + " 'status': 'triggered',\n", + " 'categories': [],\n", + " 'send_at': '2020-04-24T05:59:44Z',\n", + " 'created_at': '2020-04-23T16:49:14Z',\n", + " 'updated_at': '2020-04-24T06:00:10Z',\n", + " 'is_abtest': False,\n", + " 'abtest': None},\n", + " {'id': 'e247dfec-73f1-11ea-8b4e-fae28c37216f',\n", + " 'name': 'WSR | Newsletter ',\n", + " 'status': 'triggered',\n", + " 'categories': [],\n", + " 'send_at': '2020-04-01T13:31:22Z',\n", + " 'created_at': '2020-04-01T08:22:11Z',\n", + " 'updated_at': '2020-04-01T13:32:09Z',\n", + " 'is_abtest': False,\n", + " 'abtest': None}]" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "results.get(\"result\")" + ] + } + ], + "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": "d7e34a46dfdab62d55033522183e338b4bfd89523400494c9c14a7880471b1cb", + "notebook_path": "SendGrid/SendGrid_Get_all_messages.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/SendGrid/SendGrid_Get_Unsubscribes.ipynb b/SendGrid/SendGrid_Get_Unsubscribes.ipynb new file mode 100644 index 0000000000..870c71b263 --- /dev/null +++ b/SendGrid/SendGrid_Get_Unsubscribes.ipynb @@ -0,0 +1,242 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "85db721e-2267-40ca-ac5b-00c08ec10ff0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"SendGrid.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "2ba2f665-d276-4881-81f8-c9524f75796b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# SendGrid - Get Unsubscribes" + ] + }, + { + "cell_type": "markdown", + "id": "b55448ec-bd35-4884-b72f-a06a3f12c914", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #sendgrid #snippet #operations #dataframe #unsubscribes" + ] + }, + { + "cell_type": "markdown", + "id": "b025116f-fd57-40ae-81db-99d9dbc30445", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "70c1e871-3abb-4b63-9540-fb7a7138486e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2024-08-02 (Created: 2024-08-02)" + ] + }, + { + "cell_type": "markdown", + "id": "naas-description", + "metadata": { + "papermill": {}, + "tags": [ + "description" + ] + }, + "source": [ + "**Description:** This notebook get unsubscribes from SendGrid." + ] + }, + { + "cell_type": "markdown", + "id": "ec2132f6-bf89-4236-8ac7-0c207f8f03b1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "81f26c9b-0c3c-4cf8-ad50-dc67e6329ba1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26c428b4-66f4-48a4-82db-ff24cdec1782", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import requests\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "392e708f-7c32-45d7-8937-382c9651fc0f", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2de7b1bc-5ec9-4fa7-b89f-3f72f1b9a5e0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "api_key = \"SG.xxxxxxxxxxxxxxxxx\"" + ] + }, + { + "cell_type": "markdown", + "id": "a180347f-a2e1-44b2-bce0-775c7ac63b04", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "61983024-d97c-46d5-b27c-b7d5c7af5869", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get unsubscribes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b5d42846-8db8-4bba-b6c6-d37af7b1c138", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "def get_unsubscribes(api_key):\n", + " headers = {\n", + " \"Authorization\": \"Bearer \" + api_key\n", + " }\n", + " response = requests.get('https://api.sendgrid.com/v3/suppression/unsubscribes', headers=headers)\n", + " return response.json()\n", + "\n", + "results = get_unsubscribes(api_key)\n", + "print(\"Unsubscribes:\", len(results))" + ] + }, + { + "cell_type": "markdown", + "id": "6109e162-ea7e-4db3-bb71-41c5e1403ea1", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "b54a2952-c67e-418b-b491-40162fb75477", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a3247b7-a627-41b0-89e9-2b7c39b0be47", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "df = pd.DataFrame(results)\n", + "df" + ] + } + ], + "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": "d7e34a46dfdab62d55033522183e338b4bfd89523400494c9c14a7880471b1cb", + "notebook_path": "SendGrid/SendGrid_Get_all_messages.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}