0

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

null
    • Mconneen
    • 5 yrs ago
    • Reported - view

    From the API webinar..

    api

    I do not know if "do as server" is "required" when running on the cloud.. or suggested. 

    • hachristiansen
    • 5 yrs ago
    • Reported - view

    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 ;-)

    • Mconneen
    • 5 yrs ago
    • Reported - view

    You most likely will want to a test with ninoxApp() - returns one of "mac" | "ipad" | "iphone" | "web", identifying the type of app

    • CISOFT_Sarl
    • 5 yrs ago
    • Reported - view

    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?

    5bd096a6adc50875cd53272d

    • Mconneen
    • 5 yrs ago
    • Reported - view

    @Robert.. while it works.. You are correct.. 'Content-Type' should be in the header ...

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    What is the Ninox syntax for including the body (with an array of records), as required for an update record(s) post request?

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Westy,   The doc is correct on this one.   Assume I have a table like the following

    theDatabase

    Then the Update Record would look like.. 

    theCode

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    That is exactly what I needed. Thank you so much!

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    How can the current record be assigned to the "body" in the Update Record code above?

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Westy.. .Here is one way. 

    json

    You can also just build a well formated JOSN string.. then use the parseJSON command

    jsonFormat

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    I see now, no quotes. Also, thank you for the formatJSON and parseJSON syntax.

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    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.

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    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...

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @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.. 

    • Choices_Software_Dean
    • 4 yrs ago
    • Reported - view

    Yes, you are right. parseJSON() and text() are not needed. response.result is a JSON Object, as is. Thank you.

Content aside

  • 4 yrs agoLast active
  • 15Replies
  • 5128Views