Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Forked from angelabauer/main.py
Last active January 14, 2026 06:22
Show Gist options
  • Select an option

  • Save TheMuellenator/974c39779ec516c4c60e918c001e48ba to your computer and use it in GitHub Desktop.

Select an option

Save TheMuellenator/974c39779ec516c4c60e918c001e48ba to your computer and use it in GitHub Desktop.
Day 38 L291 - Solution: Authenticate Your Sheety API
#No Authentication
sheet_response = requests.post(sheet_endpoint, json=sheet_inputs)
#Basic Authentication
sheet_response = requests.post(
sheet_endpoint,
json=sheet_inputs,
auth=(
YOUR USERNAME,
YOUR PASSWORD,
)
)
#Bearer Token Authentication
bearer_headers = {
"Authorization": f"Bearer {YOUR TOKEN}"
}
sheet_response = requests.post(
sheet_endpoint,
json=sheet_inputs,
headers=bearer_headers
)
@Rama220292
Copy link

For some reason, the info doesn't get populated into google sheets. I have checked that the permissions are given to Sheety on my gmail account, and the data is nested in the API root.

import requests
from datetime import datetime

API_KEY = "nix_live_igDg82h4BmwMowKrwnL0TAzILSNKwXzG"
API_ID = "app_eef0ff9273e147b6859e10db"
endpoint = "https://app.100daysofpython.dev/v1/nutrition/natural/exercise"
sheety_token = "Bearer 48fnef@49%)#)@Ejdnce03r38u3rf"
sheety_endpoint = "https://api.sheety.co/121544da6b8eef4be1a71d43d91442d3/ramaWorkouts/workouts"

headers = {
"Content-Type": "application/json",
"x-app-id": API_ID,
"x-app-key": API_KEY
}

workout_data = {
"query":"ran 24km",
"weight_kg":72.3,
"height_cm":171,
"age": 33,
"gender":"male"
}

workout_info = requests.post(url = endpoint, json = workout_data, headers= headers)
result = workout_info.json()

headers = {
"Authorization":sheety_token
}

workout_date = datetime.today().strftime("%d/%m/%Y")
workout_time = datetime.now().strftime("%H:%M:%S")

for exercise in result['exercises']:

workout_input_data = {
    "workout": {
        "Date":workout_date,
        "Time": workout_time,
        "Exercise":exercise['name'].title(),
        "Duration":exercise['duration_min'],
        "Calories":exercise['nf_calories']
    }
}

workout_data_to_sheets = requests.post(url = sheety_endpoint, json = workout_input_data)
workout_data_to_sheets.raise_for_status()
print(workout_data_to_sheets)

@MANOJ91
Copy link

MANOJ91 commented Jan 14, 2026

{'sheet1': {'id': 3}} i get this output but my spreadsheet didn't change?????

for exercise in result["exercises"]:
sheet_inputs = {
"sheet1": {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment