Sign in | Sign up

Please Provide Sample Search

Tagged:

Currently contains 3 posts

Avatar

January 14, 2020 14:46

bethanybeachbum

I am trying to create a simple python file that searches the nutritionix API.
I have a working AppID and AppKey.
Status code returns 404
Can you please see simple code below and let me know what is wrong?
Thank you,
~ ~ ~ ~ ~ ~ ~ ~ ~

import requests

url = “https://trackapi.nutritionix.com/v2/natural/nutrients”
response = requests.get(url,
headers = {
“Content-Type”:“application/json”,
“x-app-id”:“<my app id>”,
“x-app-key”:“<my app key>”,
“x-remote-user-id”:“<my user name>”,
“query”:“hamburger”
}
)

print(f"Status code: {response.status_code}")

Avatar

April 20, 2020 21:40

tpanchal

import requests
import json
import datetime

def myconverter(o):
if isinstance(o, datetime.datetime):
return o.str()

def perform_service(service_url, input_data, headers_data):
json_data = json.dumps(input_data, default=myconverter)
response = requests.post(
url=service_url,
data=json_data,
headers=headers_data,
)
return response

nix_data = { “query”: “asafoetida leaf” } headers_data = { ‘Content-Type’: “application/json”, “X-APP-ID”: NUTRITIONIX_APP_ID, “X-APP-KEY”: NUTRITIONIX_APP_KEY, }
  1. nix_url = “https://trackapi.nutritionix.com/v2/search/instant”
    nix_url = “https://trackapi.nutritionix.com/v2/natural/nutrients”
    response = perform_service(nix_url, nix_data, headers_data)

Avatar

May 01, 2020 17:31

rodrigojm

I don’t know how your library in python works, but I would put that query in the URL, like this https://trackapi.nutritionix.com/v2/natural/nutrients?query=hamburguer. In the headers Also, from what I have read, x-remote-user-id is either 0 or 1. 0 for development mode and 1 for production.
Good Luck!

Reply to thread