Skip to content

Instantly share code, notes, and snippets.

@mattsilv
Last active February 27, 2024 21:39
Show Gist options
  • Save mattsilv/d99cd145cc2d44d71fa5d15dd4829e03 to your computer and use it in GitHub Desktop.
Save mattsilv/d99cd145cc2d44d71fa5d15dd4829e03 to your computer and use it in GitHub Desktop.
Nutritionix API v2: Natural Exercise Endpoint Sample
@val-afk
Copy link

val-afk commented Feb 7, 2024

import requests

APP_ID = "438a9c40" APP_KEY = "7215eb448ce325acba56b4ee224fe917"

headers = { "x-app-id": APP_ID, "x-app_key": APP_KEY, }

GENDER = "male" WEIGHT = 70.6 HEIGHT = 176.5 AGE = 20

exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise"

exercise_json = { "query": input("Tell me which exercise you did. "), "gender": GENDER, "weight_kg": WEIGHT, "height_cm": HEIGHT, "age": AGE, }

response = requests.post(url=exercise_endpoint, json=exercise_json, headers=headers) result = response.json() print(result)

output: Tell me which exercise you did. Ran 5km {'message': 'unauthorized', 'id': 'f54bca63-be81-4859-812d-00944f9fa4f3'}

Hihi, I am facing the same error. Please advice!

in your headers list where x-app_key is written, replace it with x-app-key. you have used an underscore instead of a minus sign. hope this helps because it worked for me

@BartBoxi
Copy link

Solution of how to get this done can be found here - https://gist.github.com/angelabauer/dd71d7072626afd728e1730584c6e4b8

Better to check this gits than wasting 2 hours to figure it out :)

Have fun coding!

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