I'm working on a project to build a graph based on nutritional elements of common foods. A popular source of this information is Nutritionix, which provides data via a set of APIs. I'm using MMA (v12.1) to access the API, but without success. Here is my code so far:
applicationID = "91d3b93f";
applicationKEY = "df2551cd5bdb242279928ad14417db41";
userID = 0; (* required by API*)
urlRoot = "https://trackapi.nutritionix.com/v2/natural/nutrients";
headers =
"Headers" -> {"x-app-id" -> applicationID,
"x-app-key" -> applicationKEY, "x-remote-user-id" -> userID};
qry = "Query" -> {"1 cup of flour"};
I'm providing my applicationID and applicationKEY to assist anyone who wishes to answer this question (I will change them later)
Based on the API documentation, the POST call seems simple enough. But it results in the following error:
In[18]:= results =
URLExecute[HTTPRequest[urlRoot, <|Method -> "POST", headers, qry, "ContentType" -> "application/json"|>]]
Out[18]= {"message" -> "child \"query\" fails because [\"query\" is required]", "id" -> "ddedaf39-0568-47e9-91ac-6f0764f38e58"}
I've tried a few different permutations of this, but without success.I'm hoping someone better versed in the nuances of API calls can assist me.
Thanks!