0

REST API

In the documentation for REST API it is mentioned not to put the client-side API code. Then it is mentioned that you have to use the API code to get data from a ninox database. But in practice? How do we do all this?

An example? I wish I could from a php application, click a button and get information from my database ninox, well understood it is client side in javascript that will happen, but how to format my request?

Do you have a simple example but detail javascript so that I can achieve my first action on my database ninox.

Thank you in advance for your help.

12 replies

null
    • CISOFT_Sarl
    • 5 yrs ago
    • Reported - view

    No suggestion or help?

    • blackie
    • 5 yrs ago
    • Reported - view

    I am using Advanced REST Client to test requests before I try to put them into code. It makes it easier to see the request is working and what is required without having to debug code.

    https://install.advancedrestclient.com/#/install

    • CISOFT_Sarl
    • 5 yrs ago
    • Reported - view

    Hello Blackie,

    I understand but how make you in your code for api code? you need to write the api code in your code, sample in javascript else i dont see where can i put the code if its not in client side.

    Any people for this poste?

    • CISOFT_Sarl
    • 5 yrs ago
    • Reported - view

    Any body have a sample javascript, php for REST API?

    • Birger_H
    • 5 yrs ago
    • Reported - view
    • Birger_H
    • 5 yrs ago
    • Reported - view

    If you have questions about working with Ninox, and you would like to learn the latest tips and tricks or simply want to exchange information with other Ninox users, we invite you to our webinar and the Ninox user forum:

    At our Ninox webinar tips and tricks will be presented in the first 30 minutes, the remaining 90 minutes will be used for a live support where the participants' concerns will be solved. You can register here for the webinar, which takes place every Tuesday at 18 o'clock CEST: https://zoom.us/webinar/register/WN_zoSk2qyNSz6vLRFF1zlakg

    Via the following link you will find our Ninox User Forum, where Ninox users can exchange information with each other.
    https://ninoxdb.de/en/forum/technical-help-5ab8fe445fe2b42b7dd39ee7

    • Cabinet YANTRIS
    • Romain_Zanon
    • 2 yrs ago
    • Reported - view

    Hello to all,
    I have more or less the same problem. Does anyone have a quick and easy example of how to create a query on Javascript to collect data from one of my tables?
    I've been following the documentation and the different topics on the forum, but I end up with an "Unauthorized" in my console...
    I just want to get the JSON file that would result from this and then I will work on it to modulate the information as I see fit. But for the moment I can't get it...
    (I specify, because it is perhaps one of the reasons, I am still on a 30 days trial version)

    Here is my code: (of course I've changed the URL and the API-key, in PostMan everythink works)

    <script>

    var requestURL = "http://myURL"; //link to the table of my database

    var request = new XMLHttpRequest();
    request.open('GET', requestURL, {
    Authorization: "Bearer myAPI-key",
    'Content-Type': "application/json"},
    null
    );
    request.responseType = 'json';
    request.send();

    // Server response and his treatment
    request.onload = function() {
    var ninoxFile = request.response;
    console.log(ninoxFile);   //I try to print my response in the console to see if I have what I want
    }

    </script>

    Here his the response in my console when I execute the code :

    GET https://myURL 401 (Unauthorized)
    (anonymous) @ test_NINOX_API.html:24

    If someone understands my mistake or has some tips, I'm interested :)

    Thanks in advance !

    • Nick_Massie
    • 2 yrs ago
    • Reported - view

    I have had good luck using the shared view code JSON file.  This provides a great reference because it is basically WYSIWIG of the Table View useing the value of the fields even those from related tables.  

    • Cabinet YANTRIS
    • Romain_Zanon
    • 2 yrs ago
    • Reported - view

    Hello Sean,

     

    Thank you for your response and your help ! Few times after had sent my question, I've resolved my problem and here you can see my code (maybe for the next people who wants code in JS to import his data) :

    <script>
       function ninoxAPIRequest (url) {
          let requestURL = url; //URL linkURL to your JSON data

          let request = new XMLHttpRequest();
          request.open('GET', requestURL, true);
          request.setRequestHeader("Authorization","Bearer 'your Ninox API-KEY'");
          request.setRequestHeader('Content-Type', 'application/json');
          request.responseType = 'json';
          request.send();

          // Server response and his treatment
          request.onload = function() {
             let ninoxFile = request.response; //this variable contain the JavaScript object based on the JSON
             console.log(ninoxFile);
          }

       }

       requestNinoxDossier = 'enter your url here (use Postman to see if your request is good or not';
       ninoxAPIRequest (requestNinoxDossier);
    </script>

    I hope this response will help some new coders like me ^^'

    • Sean
    • 2 yrs ago
    • Reported - view

    Romain, thanks for sharing. I'm a complete novice with making http calls via JavaScript, but I've looked into it. I'm curious about why you chose XMLHttpRequest() instead of fetch().

    • Cabinet YANTRIS
    • Romain_Zanon
    • 2 yrs ago
    • Reported - view

    The reason is pretty simple. I'm very very novice in coding and I've made an example with XMLHttpRequest in class, and I used this to make my project. But I know, in the near future the fetch() method will be more used than XMLHttpRequest() method. Additionly I've seen in some forum that the fetch() method is little bit too recent and all the browser not support it (for the moment, maybe is the not the case today).

    But, I think if you prefer the fetch() method you can use it also.

    For what I want to do, the XMLHttpRequest() method function perfectly ^^

Content aside

  • 2 yrs agoLast active
  • 12Replies
  • 3873Views