Support
One-on-One consulting and assistance based on your specific and unique needs
Media
Development tips from various members of our Nioxus team
Get the help you need from the experts at Nioxus. Contact Us >
Get the help you need from the experts at Nioxus. Contact Us >
Media
Keep up to date with Nioxus tips, tricks and products
Get the help you need from the experts at Nioxus. Contact Us >
Support
Receive discounts if you have a membership
Media
Learning about Nioxus and a few of our clients
Get the help you need from the experts at Nioxus. Contact Us >
VOLUME XCVIII 09/16/2021nn
In this article we will look into a powerful Ninox API endpoint, /query. This endpoint lets you specify a Ninox script to execute on a database. There are many applications of this endpoint including but not limited to, getting the value of a formula field (not accessible from other routes in the API), filtering the records based on any criteria, or performing some action in your database.
There are two ways to specify a script to the /query endpoint: in the URL, or the body of the request. To specify the script in the URL, the script is placed as a query parameter called “query”. This looks like: https://api.ninoxdb.de/v1/teams//databases//query?query=. In this variation, the method of the request is GET.
To specify the script in the body of the request, send a POST request to https://api.ninoxdb.de/v1/teams//databases//query with a JSON body in the following format:
{“query”: “”}
I find that this method is easier since the url does not support spaces and other certain characters that you may need to use in a Ninox script. It is possible to send multiple lines of code to this endpoint. For example, you could send the the following request body:
{“query”: “let x:= 5; 2 + x”}
The response returned from this request would be 7.
It is also possible to call a global function via this endpoint. For example, if you have a function called “doSomething()” defined in “global script definitions” (found in admin mode on the options page of your database), this can be called in the script sent to the endpoint like so
{“query”: “doSomething()”}
I hope that this article has been helpful and that you can make use of this powerful endpoint in your application!
CLICK IMAGE TO ENGLARGE
Join us tomorrow at 12:00pm ET or 6:00pm CET for our Learning Lab! This week we’ll be doing an open Q&A so remember to bring lots of questions!
Did you know that Nioxus has built over 130 templates which are available to all Standard, Deluxe and Premier Nioxus members?
Nioxus has created nearly 100 videos and over 200 hours of content teaching you how to use and optimize Ninox, as well as our supplementary products, CalendarPLUS, ReportsPLUS and DocumentsPLUS!
I heard some people are having issues with Ninox API functions. Especially talking about API responses. Ninox had an update around the first of this month and that broke some functions that worked before. To discuss this issue and the solution we have to go through a few things first.
When we receive an API response for a request we receive a JSON Object. An object has properties that we can access. Example:
{
id: 1,
name: “Jon Doe”,
age: 35
}
This is a simple object. Let’s see an example for an array:
[
{
id: 1,
name: “Jon Doe”,
age: 35
},
{
id: 2,
name: “Jane Doe”,
age: 33
}
]
Notice in the first example only a curly braces surrounding the response that includes key-value pairs versus in the second example we have the square brackets surrounding the individual objects and the objects are separated by a comma. This will be important later.
A typical request looks like:
let REQUEST := do as server
http(“GET”, “https://api.ninox.com/…“, {Authorization: “Bearer ” + TOKEN,‘Content-Type’: “application/json”}, {})
end;
Then we get a response. If we receive an object as a response instead of an array we can access the properties immediately (note that that first property is always “result” and properties are case sensitive) by adding a “dot” after the variable name we used to store the response. Usually we have to “wrap” this around with the text() function to be able to save it in a text field or print it, etc:
text(REQUEST.result)
If we would like to access what’s inside that object then we just add another “dot” and then the KEY name:
text(REQUEST.result.name)
This is where issue happens. The line above worked before. Now it has stopped working. To fix this we need to modify the code. First we have to wrap the response around with the text() function then with the parseJSON() to covert the result object. Now we are able to continue as before:
parseJSON(text(REQUEST.result)).name
This will return the desired result, it will read out the name from the name property.
If the result returns an array then we have to loop though the retuned objects by using the “for i in range(cnt(REQUEST.result)) do…” loop combined with the item(REQUEST.result, i).name to access the name property from each objects for example.
All logos, trademarks and names are the protected property of Nioxus Corporation or their respective owners.
“Ninox,” “Ninox Database” and the blue Ninox owl eye logo are the property of Ninox Berlin and are used with permission.