-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4308ae8
commit acc56cc
Showing
5 changed files
with
1,467 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,305 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "85db721e-2267-40ca-ac5b-00c08ec10ff0", | ||
"metadata": { | ||
"papermill": {}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"<img width=\"8%\" alt=\"SendGrid.png\" src=\"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/.github/assets/logos/SendGrid.png\" style=\"border-radius: 15%\">" | ||
] | ||
}, | ||
{ | ||
"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 | ||
} |
Oops, something went wrong.