-
-
Save angelabauer/dd71d7072626afd728e1730584c6e4b8 to your computer and use it in GitHub Desktop.
This file contains 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 requests | |
GENDER = YOUR GENDER | |
WEIGHT_KG = YOUR WEIGHT | |
HEIGHT_CM = YOUR HEIGHT | |
AGE = YOUR AGE | |
APP_ID = YOUR APP ID | |
API_KEY = YOUR API KEY | |
exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise" | |
exercise_text = input("Tell me which exercises you did: ") | |
headers = { | |
"x-app-id": APP_ID, | |
"x-app-key": API_KEY, | |
} | |
parameters = { | |
"query": exercise_text, | |
"gender": GENDER, | |
"weight_kg": WEIGHT_KG, | |
"height_cm": HEIGHT_CM, | |
"age": AGE | |
} | |
response = requests.post(exercise_endpoint, json=parameters, headers=headers) | |
result = response.json() | |
print(result) |
"Weight Kg not allowed"
Check your endpoint.
It should be v2/natural/exercise
You have v2/natural/nutrients and for that endpoint Weight Kg is not a valid parameter.
That documentation is so hard to understand, couldn't find query parameters for some reason.
That documentation is so hard to understand, couldn't find query parameters for some reason.
It's there it's just tucked under and expand menu which was not the easiest to find.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got mine working eventually - persistence and resilience :)
Here is my code below. I have put a few pointers in brackets in my code to highlight the areas were I was getting problems.
Hope this is of some help :)
import requests
exercise = input("Please tell us what exercise you have done?")
APP_ID = "xxxxxxxxx" (Make sure your APP_ID is submitted as a string)
APP_KEY = "xxxxxxxxxxxxxxxxxxxxxxxx " (Make sure the APP_KEY is a string and a carbon copy of what appears in your account, just take off the final -, but leave the dead space at the end)
API_ENDPOINT = "https://trackapi.nutritionix.com/v2/natural/exercise"
headers = {
"x-app-id": APP_ID,
"x-app-key": APP_KEY
}
parameters = {
"query": exercise,
"gender": "male", (Please note the gender is a string but the weight, height and age are all integer values)
"weight_kg": 56,
"height_cm": 120,
"age": 35
}
response = requests.post(API_ENDPOINT, headers= headers, json= parameters)
print(response)
result = response.json()
print(result)