http
To send an HTTP request
With this function, you can make an API call to access data outside your current database. You can integrate some external services or exchange data between 2 databases.
This function can take up to 4 parameters:
- Method A string defining the HTTP method for the API call. This is usually
"GET"
,"POST"
,"PUT"
, or"DELETE"
- URL A string holding the URL to the external service
- Header An optional JSON object containing meta information of the API call like an API key or the content type.
- Body An optional JSON object usually containing the data that will be shared with other external services.
Using API might need some extra knowledge. Learn more about API.
To access a Ninox database you need an API key.
We recommend executing this function together with
do as server...end
. More about optimizing performance of scripts.
Syntax
http(string, string)
http(string, string, JSON)
http(string, string, JSON, JSON)
With files
http(string, string, JSON, [file])
http(string, string, JSON, JSON, [file])
Return
JSON
Examples
http(method, url)
To call REST services without a header or body.
http(method, url, header)
To call REST services—the method and URL are strings; the (optional) header is a JSON object.
http(method, url, header, body)
To call REST services—the method and URL are strings (header and body are optional objects).
let url := "https://api.ninoxdb.de/v1/teams/" + teamId() + "/databases/" + databaseId() + "/tables/";
let myAPIKey := "Bearer abcd1234-0000-xxxx-zzzz-1a1aa1aaa1a111";
let response := http("GET", url, {
Authorization: myAPIKey
}, null);
response
Result: You will receive a JSON object either containing all tables of the database if the API call is successful, or a JSON object containing an error message if not.
do as server
let url := "https://api.ninoxdb.de/v1/teams/" + teamId() + "/databases/" + databaseId() + "/query";
let APIKey := "Bearer abcd1234-0000-xxxx-zzzz-1a1aa1aaa1a111";
let response := http("POST", url, {
Authorization: APIKey,
'content-type': "application/json"
}, {
query: "select Kunden where Status = 4"
});
response
end
Result: You will receive a JSON object either containing all records of the Customers table, where the Status = 4, if the API call is successful or a JSON object containing an error message if not.
With files
http(method, url, header, files)
To call REST services and include a list of files - the method and URL are strings; the (optional) header is a JSON object.
http(method, url, header, body files)
To call REST services and include a list of files - the method and URL are strings (header and body are optional objects).
See also
More about API calls in Ninox script