Created
October 2, 2023 19:07
-
-
Save phil-loops/b95c7d8c3a79444fee0241a70cc3ddde to your computer and use it in GitHub Desktop.
CSV --> Loops Api
This file contains hidden or 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
| import csv | |
| import requests | |
| import time | |
| file_path = 'my-csv.csv' | |
| headers = {"Authorization": "Bearer ......"} | |
| # Open the CSV file | |
| with open(file_path, newline='') as csvfile: | |
| # Create a CSV reader object | |
| csvreader = csv.reader(csvfile) | |
| next(csvreader) # Skip header row | |
| # Loop through each row in the CSV file | |
| for row in csvreader: | |
| # Prepare the data for the API | |
| data = { | |
| "firstName": row[0], | |
| "email": row[1], | |
| "cohort": row[2], | |
| "status": row[3], | |
| } | |
| print(f'Sending data for {data["email"]}...') | |
| response = requests.post('https://app.loops.so/api/v1/contacts/update', json=data, headers=headers) | |
| print(f'Status code: {response.status_code}') # Print the status code for each request | |
| time.sleep(.25) # Avoid rate limiting | |
| print('Done!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment