### Clear Action Items for Creating and Using Public Notion Integrations --- ### Step 1: Create a

Archive Button
Tags
Action Items
Created by
Umair Kamil
Created time
Jul 29, 2024 7:39 AM
deadline
July 30, 2024 → July 31, 2024
Last edited by
Umair Kamil
Last edited time
Jul 29, 2024 7:39 AM
status
Archived
platforms
TwitterLinkedIn
media_type
Text
type
Thread

### Clear Action Items for Creating and Using Public Notion Integrations --- ### Step 1: Create a Public Notion Integration 1. **Log into Notion** - Go to [My Integrations](https://www.notion.so/my-integrations) on the Notion website. 2. **Create a New Integration** - Click on **+ New integration**. - Name your integration. - Select your target workspace. 3. **Set Integration Capabilities** - Choose the required capabilities for your integration. - Submit the settings. 4. **Choose Integration Type** - Select **Public integration** under the Integration type field. 5. **Fill Required Fields** - Enter the Redirect URIs. - Provide: - Company name - Website - Privacy policy link - Terms of use - Support email 6. **Save Credentials** - Save the OAuth client ID, client secret, and authorization URL for later use. --- ### Step 2: Create a Table to Share 1. **Within Notion, create a new table** - Navigate to your chosen workspace and create a new table. 2. **Configure Columns** - Create two text columns named **handle** and **tweet**. 3. **Name the Table** - Assign a meaningful name to your table. --- ### Step 3: Create Notion OAuth 2.0 Authorization Flow 1. **Generate Authorization URL** - Use the following Python code to generate the authorization URL: ```python import base64 import urllib.parse oauth_client_id = "YOUR_OAUTH_CLIENT_ID" oauth_client_secret = "YOUR_OAUTH_CLIENT_SECRET" redirect_uri = "YOUR_REDIRECT_URL" parsed_redirect_uri = urllib.parse.quote_plus(redirect_uri) auth_url = f"https://api.notion.com/v1/oauth/authorize?owner=user&client_id={oauth_client_id}&redirect_uri={parsed_redirect_uri}&response_type=code" print(auth_url) ``` - Output the generated URL and direct users to visit this URL to authorize the integration. 2. **Exchange Authorization Code for Access Token** - Extract the authorization code from the redirect URL resp

onse. - Use the following Python code to exchange the authorization code for an access token: ```python auth_code = "EXTRACTED_AUTH_CODE" key_secret = f'{oauth_client_id}:{oauth_client_secret}'.encode('ascii') b64_encoded_key = base64.b64encode(key_secret).decode('ascii') auth_resp = requests.post( "https://api.notion.com/v1/oauth/token", headers={"Authorization": f"Basic {b64_encoded_key}"}, data={"grant_type": "authorization_code", "code": auth_code, "redirect_uri": redirect_uri} ) access_token = auth_resp.json().get("access_token") ``` --- ### Step 4: Add Data to Authorized Table 1. **Search for Database ID** - Use the `access_token` to search for the authorized databases and note down the `database_id` of the relevant database. 2. **Add Data to Notion Table** - Prepare the data to be added. - Use the following Python code snippet to add the data into your Notion table: ```python example_data = {"handle": "@SomeHandle", "tweet": "Here is a tweet"} payload = { 'parent': {'database_id': notion_database_id}, 'properties': { 'title': {'title': [{'text': {'content': example_data['handle']}}]}, 'tweet': {'rich_text': [{'type': 'text', 'text': {'content': example_data['tweet']}}]} } } response = requests.post( 'https://api.notion.com/v1/pages', headers={ "Authorization": f"Bearer {access_token}", "Notion-Version": "2021-08-16", "Content-Type": "application/json" }, data=json.dumps(payload) ) ``` --- By following these clear action items, you will be able to set up and use public Notion integrations effectively, authenticate users, obtain access tokens, and add data to shared Notion databases.