API call on foreign API from Ninox WebApp
I'm trying to retreive Information from OpenProject API. The following Code works in my iPad, but not in Chrome:
let response := http("GET", "Openproject URL/api/v3/users/{my User Number}", null, {
/*Authorization*/
});
if response.error then
alert("Error!")
else
alert(text(response.result))
end
Is it possible to use REST API in the Ninox Web App and I am missing something or is it only possible in compiled apps?
As with "it works" I mean to get the right Result-JSON, not just
{"error":"Request failed: error - "}
as an response.
Sincerely,
Hauke
15 replies
-
From the API webinar..
I do not know if "do as server" is "required" when running on the cloud.. or suggested.
-
Thank you very much, that was the missing part indeed!
Now I have to check if the function still works on iPad and maybe alter it a bit ;-)
-
You most likely will want to a test with ninoxApp() - returns one of "mac" | "ipad" | "iphone" | "web", identifying the type of app
-
Hello,
Why you write this?
A. is for header and B. also
I dont understand. I thought it would be necessary to write this according to the documentation:
let response := do as server
http("GET","https://api.ninoxdb.de/v1/teams/"+myTeam+"/databases", null, {
Authorization: "Bearer API-Key",
'Content-Type': "application/json"
})end;
....
I'm right?
-
@Robert.. while it works.. You are correct.. 'Content-Type' should be in the header ...
-
What is the Ninox syntax for including the
body (
with an array of records), as required for an update record(s) post request? -
@Westy, The doc is correct on this one. Assume I have a table like the following
Then the Update Record would look like..
-
That is exactly what I needed. Thank you so much!
-
How can the current record be assigned to the "body" in the Update Record code above?
-
@Westy.. .Here is one way.
You can also just build a well formated JOSN string.. then use the parseJSON command
-
I see now, no quotes. Also, thank you for the formatJSON and parseJSON syntax.
-
When I GET a record, the response.result looks like a valid JSON string, however, when I attempt to apply parseJSON() to the response.result, it is not recognized as a function. What might I be doing wrong. I have looked around for examples of parseJSON(), but have not found any.
-
When I use
parseJSON(text(response.result))
the parseJSON function is recognized. That is encouraging, but I now get a "not recognized as a record" error when I attempt to access a field in the object. I will work on it some more... -
@Westy.. Not following 100% .. unfortunatly ..... mutitasking .. :( So.. YES.. your second one works... becuase response is already a JSON Object... and is why your first one fails..
-
Yes, you are right.
parseJSON()
andtext()
are not needed.response.result
is a JSON Object, as is. Thank you.
Content aside
- 5 yrs agoLast active
- 15Replies
- 5161Views