Integration and HTTP
Learn how to call external services, validate XML against XSD schemas, transform XML, send emails with Ninox scripts.
Integration functions connect your app to services and communication tools outside Ninox. You can call APIs, validate XML against schemas, transform XML, and send emails.
In this chapter, you will learn how to:
Call external services with HTTP.
Transform XML.
email()
Return or reuse an email value
formatXML()
Convert JSON data to XML text
http()
Send an HTTP request
parseXML()
Convert XML text to a JSON object
Call external services
Use these functions to call any REST API, to pull data from another service or push data between Ninox databases.
Call an API with http()
Use http() to send a request to an external service.
Use it when you want to:
Fetch data from, or send updates to another system.
Connect Ninox to REST APIs and other Ninox databases.
Don't place http() inside do as transaction...end
Transactions use a single-threaded write queue. An HTTP call inside a transaction blocks all other writes until the request finishes. The app does not hang forever, but every pending write waits for the full duration of the call. That can make the app feel slow.
http(method, url)
http(method, url, body)
http(method, url, header, body)
http(method, url, header, body, files)
methodtext value of the HTTP method , for example,"GET"or"POST"urltext value of the endpoint URLheaderoptional headers as a JSON object, for example,{ Authorization: token }bodyoptional request body as a JSON objectfilesoptional files to upload as[file]when the current execution context supports file uploads (server context)
A body is required when accessing Ninox data
If you use http() to access data in Ninox, a body must be passed. If no information needs to be passed in the body, it simply remains empty. An example of this would be:
http("GET", "https://api.ninox.com/v1/[...]", {Authorization: "Bearer xxxx-xxxx-xxxx", "content-type": "application/json"}, {})
Let’s take a look at some examples:
Calls the external service and returns a JSON response object or an error object.
Lists tables from the current database through the Ninox API or an error object.
Sends a POST request and returns matching records or an error object.
Uploads a file to an external service when file uploads are supported in the current execution context.
Tips:
http()returns a JSON object, not plain text.If you access another Ninox database, you need an API key.
Some endpoints expect a body even for
GETrequests. Use{}when the target endpoint requires one and you do not need to send fields.File uploads depend on the execution context.
Test integration scripts against the real service response, not sample output only.
Transform XML
Use these functions when another system sends or expects XML, especially when the XML must match a defined schema.
Convert XML text to data with parseXML()
Use parseXML() to turn XML text into a JSON object you can inspect in Ninox. This is especially useful when you connect Ninox to external services by API and need to process XML responses. XML is a common exchange format alongside JSON.
Use it when you want to:
Read values from an XML response.
Extract fields from imported XML.
Convert XML into structured data for later logic.
parseXML(string)
stringthe XML text you want to convert to a JSON object
Let’s take a look at some examples:
Returns a JSON object built from the XML text, for example:
Tip:
If you have an XSD schema, validate external XML before you parse it.
Create XML text with formatXML()
Use formatXML() to convert JSON data into XML text.
Use it when you want to:
Prepare XML for another service.
Reformat parsed data into readable XML.
formatXML(JSON)
formatXML(JSON, boolean)
JSONthe structured data you want to convert to XMLbooleanwhether the output should be visually structured for reading
Let’s take a look at some examples:
Formats the parsed object back into readable XML text.
Converts the JSON object into structured XML text. Keys like @type become XML attributes. @ becomes the node text value.
Tips:
Use the pretty option when humans need to read the result.
Use compact output when the target system only needs the payload.
This function is especially useful for API integrations that expect XML instead of JSON.
Send email messages
Use this function to open an email message from Ninox.
Work with an email value using email()
Use email() to convert text into an email value.
Use it when you want to:
Open your device's email app from an email value.
Display a formula field as an email field.
Extract an email address from text and use it with one click.
email(string)
stringthe text value to use as an email address. Include an@and a valid domain.
Let’s take a look at some examples:
Converts the value in myEmail into an email value.
Displays the address as an email value with a clickable mail action.
Tips:
Keep email addresses correctly formatted. Otherwise, the mail action can return an error.
A correctly formatted address opens your device's default email app.
Last updated
Was this helpful?