I’ve used Classy to fundraise for Golden Harvest Food Bank for about four years. It’s a great platform, and we’ve raised nearly $3.5 million with it in that time. One of our biggest fundraisers, It’s Spooky to Be Hungry, used Classy to raise more than $300,000 last year. It is a peer-to-peer fundraiser with nearly 500 teams raising money.
Since Spooky is an annual event, we have a lot of teams that come back year after year. One of the pain points has been getting their teams set up. One at a time is easy, but if you’re talking about hundreds of teams, you’re looking at hours of data entry. Sure, they can do it themselves, but doing it for them removes some of the friction that might prevent them from getting involved.
I’m lazy, so I created a Python program to access the Classy API to upload hundreds of teams at the touch of a button. I’m going to walk you through it for you so you can do it, too.
I’m going to show you two different ways to do it. The first is for people who have very little familiarity with coding. The second will be for people who know their way around VS Code.
Introducing Google Colab
Google Colab is a tool that Google has created to allow people to program interactively on the web. I’ve written a post about starting in Colab from scratch, which also shows how to make cool branded QR codes. If you have a gmail account, open this prepared notebook, which already contains the code you need.
After it opens, save yourself a copy:
Now you have your very own Jupyter notebook with the program that you need to run the Classy API. Now you need to do a few more steps to set up. You’re going to need to create and upload two additional files for this to work.
Create your API key
To create your ‘auth’ file, you’ll have to create an API project in Classy. It will give you an API Key and Secret, which is a special password that enables you to access the database system directly through the API (Application Program Interface). This sounds hard, but is pretty easy to do. On your Classy Manager page, click the “Apps & Integrations Tab and then the Classy API button.
This will take you to a page that will enable you to name a new API app. Use your new app only for this program, so that you can delete the app key without affecting any other apps that you might have.
When you hit create app, the system will generate an id and key that you want to save as a json file. Open your notepad app and copy the following into the blank file:
{ "Classy_ID" :"Replace with your classy ID", "Classy_Secret" :"Replace with you Classy Secret" }
Replace the text in quotes on the right with your new ID and Secret. Save this on your desktop as a .txt file. If you don’t see extensions, follow this guide to show them. Then rename the file so that the extension is .json instead of .txt. Now you have your very own auth file.
Create your list of teams
Next, you’re going to create a .csv file. CSV stands for “Comma Separated Values,” one of the oldest ways of storing tabular data. You can use Excel to create it, just when you save it, choose “save as .CSV” instead of “save as .xlsx”.
The data you need for your CSV will look like this when it’s done:
name,designation_id,raw_goal This is a team name,1821026,500 This is another team name,1821026,500
If you’re creating it in Excel, just leave out the commas and make sure that you delete any spaces at the end of any line. They can cause problems. Also, the team names should not contain any apostrophes or quotation marks. That little ‘ or ” will throw off the program. If the name absolutely requires it, create the team without it and then change the name in the Classy Manager.
The second number in the row is the designation ID. This identifies the program that the team will fund for record-keeping purposes.
The final number is the fundraising goal for the team.
The nice thing about this CSV is that it can contain one row or a thousand. The python script will burn through them one at a time, creating the teams via the API.
Putting the pieces all together.
You’re almost there. The next step is to upload the two files that you just created to google drive. This is easy to do in Colab. Just click on the folder icon on the left to open up the file system.
If you click the little box in the first cell (Where the ‘1’ is) that looks like a play button, a you’ll be asked to allow Colab to access your Google drive. Follow the instructions that say yes, and folder called MyDrive will show up. If it doesn’t show up immediately, click the folder refresh icon above.
Drag and drop your new auth and csv files into MyDrive. You’re almost done. When you hover over the files in the file pane, you’ll see three little dots. Clicking on the dots will show you several options. Choose “Copy File Path.”
Copy the file path for auth.json and paste it in the quotation marks where the auth fil is in the second code cell. Copy the file path for the CSV file and paste it in the quotations where the csv file is located.
The last thing to do is to update your campaign ID. You find the ID on the campaign page in Classy.
Take the number from the campaign and write it over 520261.
If all that’s done, then you should be able to press the play button on the second cell. It should spin a few seconds before you see a message that looks like this.
Troubleshooting.
The only problem that I ran across with this script is making sure that you have the right permissions in Classy. The person creating the API key needs to have Administrator-level permissions, as far as I know. Also, you can’t have any required fields for teams to fill out. Just turn that button off at the campaign level. You can turn it back on after you run the API script, but having it active when you run it can cause an error.
VS Code: For the Coders.
If you’re familiar with VS Code, here’s an easy way to do all of the above. Follow the instructions above to create your auth.json and csv file. Then save the following into a .py file:
import os import json import requests import pandas as pd # Read the client ID and secret from the Auth.json file auth_file = "Classy_CC\Auth.json" #Replace this with the path and name of the JSON file that has your Classy API key with open(auth_file, "r") as f: auth_data = json.load(f) client_id = auth_data["Classy_ID"] client_secret = auth_data["Classy_Secret"] campaign_id = 520261 #this should be your campaign id csv_file = "Classy_CC/Classy_Teams_APi/OneTeam.csv" #Replace this with the path and name of the csv file of the teams you want to create in Classy df = pd.read_csv(csv_file) def get_access_token(client_id, client_secret): # Create the token request payload payload = { "grant_type": "client_credentials", "client_id": client_id, "client_secret": client_secret, } # Make a POST request to the token endpoint response = requests.post("https://api.classy.org/oauth2/auth", data=payload) # Check if the request was successful if response.status_code == 200: access_token = response.json()['access_token'] response_data = response.json() json_file_path = 'Classy_CC/Classy_Teams_APi/response_data3.json' with open(json_file_path, 'w') as json_file: json.dump(response_data, json_file, indent=4) print(f"Response data saved to '{json_file_path}'.") return access_token else: print(f"Failed to retrieve access token. Error: {response.text}") return None access_token = get_access_token(client_id, client_secret) # Check if the access token was successfully retrieved if access_token: headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json", } print(access_token) else: # Exit or handle the error accordingly exit(1) for index, row in df.iterrows(): team_name = row["name"] fundraising_goal = row["raw_goal"] designation_id = row["designation_id"] # Create team payload payload = { "designation_id": designation_id, "name": team_name, "goal": fundraising_goal, "currency_code": "USD" } # Make POST request to create team response2 = requests.post( f"https://api.classy.org/2.0/campaigns/{campaign_id}/fundraising-teams", headers=headers, json=payload, ) response2_data = response2.json() # Check if the request was successful if response2.status_code == 200: print(f"Team '{team_name}' created successfully.") else: json_file_path2 = 'Classy_CC/Classy_Teams_APi/response_data2.json' with open(json_file_path2, 'w') as json_file: json.dump(response2_data, json_file, indent=4) print(f"Response data saved to '{json_file_path2}'.") print(f"Failed to create team '{team_name}'. Error: {response2.text}") print(response2)
Update the campaign codes and the designation codes in the CSV file and you should be ready to rock and roll.
Getting more out of Classy
This has proven to be a very useful and fast way to create new teams in our It’s Spooky to Be Hungry campaign. I’ve created some other useful Classy API scripts. If you’re interested, shoot me an email at nathan@thealmoner.com.