Skip to content

Instantly share code, notes, and snippets.

@phil-loops
Created October 2, 2023 19:07
Show Gist options
  • Select an option

  • Save phil-loops/b95c7d8c3a79444fee0241a70cc3ddde to your computer and use it in GitHub Desktop.

Select an option

Save phil-loops/b95c7d8c3a79444fee0241a70cc3ddde to your computer and use it in GitHub Desktop.
CSV --> Loops Api
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