Sign in | Sign up

Search is always pulling null for Nutrients

Tagged:

Currently contains 5 posts

Avatar

April 10, 2015 03:05

hershanand

Hello, I just started using this API v2 and no matter what I search for the query, the nutrients in results always shows null. Can someone please help me with this? Is there something I am missing because all the other values show up fine. Thank you.

Avatar

April 10, 2015 15:22

Matt Silverman

Hi, can you please post the exact query you are submitting to the API (without your API key/appID). Thanks!

Avatar

April 10, 2015 19:28

hershanand

I’m using the input text from the user and storing it in a variable called “search”. I then create the following object which I send via an AJAX request which returns the data:

var fields = {
‘q’: search, //input text variable from user
‘limit’: 50,
‘offset’: 0,
‘search_type’: ‘restaurant’,
‘search_nutrient’: ‘calories’,
‘appKey’: appKey, //appKey variable
‘appId’: appId //appID variable
};

The returned data from the AJAX request works, but like i mentioned, it only returns null for the nutrients field.

For reference, here is my AJAX call and you can see I console log the nutrients:

$.ajax({
type: ‘GET’,
url: ‘https://apibeta.nutritionix.com/v2/search/’,
dataType: ‘json’,
data: fields,
}).done(function(rsp){
var i = 0;
data = rsp.results;
while(i < data.length) {
console.log(data[i].nutrients);
i++;
}
}).fail(function(err){
//Log Error
console.log(err);
});
}

Avatar

April 15, 2015 02:10

hershanand

any update? please let me know, thanks so much.

Avatar

April 28, 2015 14:17

yesdev_1

Similar Issue. Even if you get to a list of 1, the query never returns exact. What Id’s did you get in your response? This is the message I sent to the company last week…

Strange Resource Id’s returned for query
Hello,

I am hitting the V2 Search API and finding 2 things.

I cannot get exact=true as a result even for queries that return 1 result. This is preventing me from returning the array of nutrients

The resource Ids returned to not match the expected values. Instead of a the long string (example 513fceb575b8dbbc21001502), I am getting values like r83ZuAxRq and 0EAbFjKng.

As such I cannot even call the specific item search to get those values back.

Thank you in advance for your advice and time!

Reply to thread