Guides
GuidesLog In
Guides

API Best Practices and AI Precautions

Use the DataNinja API and DQL safely, including with AI tools and agents

The DataNinja API and DataNinja Query Language (DQL) let your team pull data into reports, connect other systems, and automate routine work. More and more often, that work involves AI tools: a chatbot that writes a DQL query, a script an AI assistant wrote for you, or an AI agent that calls the API on its own. This page covers how to use the API safely, with extra precautions for AI.

For how DQL, the API Explorer and the API work, see Utilizing DQL and the DataNinja API.

🚧

The API Works on Live Data

Anything a script or AI tool does through the API happens in your real DataNinja site, the same as if a user did it. Changes are recorded under the token owner's name, and they can sync to NetSuite or QuickBooks Online. There's no undo button for a script that went wrong, so test first and start small.


Before You Start

Start With the Goal

Before writing a script or connecting an AI tool, be clear about what you need. If you want the same data on a schedule, a report or a single scheduled export is often simpler and lighter on your site than a script that queries everything. Open a chat with our Support team and tell us what you're trying to accomplish; we may already have a report that does it.

Test in a Sandbox

Build and test every script, integration and AI workflow in a sandbox site before it touches production. Your sandbox can be connected to a NetSuite or QuickBooks Online sandbox, so you can see what syncs without affecting your books. To set up a sandbox, reach out to our Implementation team.

📘

Copying a Sandbox to Production

If your sandbox is copied to production during implementation, any API tokens created in the sandbox come along with it. Revoke them and create new tokens in production.

Use a Dedicated Integration User

Create a separate DataNinja user for each integration or AI tool, instead of using a person's account. Give that user only the roles it needs (see Permissions and User Management). This keeps the tool's changes easy to find in the history, and you can switch it off without affecting anyone else.


Manage API Tokens

Scripts and tools sign in to the API with an API token. A token carries its owner's roles and permissions, so anyone who has your token can do anything you can.

API tokens tab on the user profile with a named token and its expiration date
  • Create a token per tool. Open your user profile, go to the "API tokens" tab, and create a token with a name that says what it's for, such as "Power BI export". You can have up to 10 active tokens.
  • Copy it right away. The token is shown only once. Store it in a password manager or secrets vault, never in a script, spreadsheet, shared document or chat.
  • Send it in the header. Send the token in the ApiToken header of each request.
  • Plan for expiration. Tokens expire one year after they're created. Note the expiration date and create a replacement before then so your integration doesn't stop.
  • Revoke what you don't use. Revoke a token as soon as a tool or integration is retired, or if you think it was exposed. Tokens are revoked automatically when their user is disabled, deleted or made a contractor.
🚧

Username and Password Sign-In No Longer Returns a Token

Older scripts that exchanged a username and password for a token need to be updated to use a token from the "API tokens" tab. Never put a username or password in a script or give them to an AI tool.


Keep Your Site Fast

A script or AI agent that sends a lot of requests, or very large queries, can slow your site down or cause errors for everyone using it. A query that runs longer than 30 seconds stops, and when your site is busy, requests can fail with "Too many requests, try again later."

  • Ask for only what you need. Select specific fields instead of SELECT *, filter with WHERE, and use LIMIT and OFFSET to page through large results.
  • Don't copy every object. Pull the records you need, and where you can, only the ones that changed since your last run.
  • Schedule sensibly. Run scheduled jobs at the longest interval that works for you, and outside your busiest production hours when possible.
  • Back off on errors. If a request fails, wait before retrying, and stop after a few attempts. A script that retries instantly in a loop can overload your site.
  • Run one job at a time. Avoid starting several heavy scripts or agents at once.

DQL also has built-in limits. The full list is on the API Explorer page.

LimitValue
Rows returned by a queryUp to 3,000 (page through more with LIMIT and OFFSET)
Child queries per query5
Rows returned per child query100 by default, up to 250
Relationship depth in a dotted path (such as Customer.Name)6
Query timeout30 seconds

Writing Data Through the API

API writes follow the same rules as the DataNinja UI: the token owner's permissions, the same validation, and the same history. Because they're real transactions, a mistake repeated by a script can create many bad records quickly.

  • Check before you create. Look up whether a record already exists before creating it, so a rerun doesn't create duplicates.
  • Start with a few records. Run a write job on a handful of records, check the results in DataNinja and in your financial system, then run the rest.
  • Watch your financial system. Changes made through the API can sync to NetSuite or QuickBooks Online the same way changes in the UI do. Check the Sync Page after a bulk change.
  • Leave approvals to people. Approvals and e-signatures require the signer's own credentials. Don't build automations that sign on someone's behalf.

Using AI Tools With DataNinja

AI tools can help you write DQL queries, build reports and automate tasks. They can also make confident mistakes, and an AI agent can act much faster than a person. Treat an AI tool like a new team member who hasn't been trained on DataNinja yet.

Protect Your Data

  • Check your company's AI policy first. Find out which AI tools your company has approved, and check the AI vendor's terms for how your data is stored and whether it's used for training.
  • Share as little as you can. Send the AI tool only the fields it needs. Leave out customer details, pricing and other sensitive information unless they're required.
  • Never paste tokens, usernames or passwords into a prompt. If you've pasted a token into a chat, revoke it and create a new one.

Check Everything an AI Writes

  • Confirm field and object names. AI tools often guess field names that don't exist in DataNinja. Confirm them in the API Explorer before running a query (see Utilizing DQL and the DataNinja API).
  • Read the script before you run it. Make sure a person understands what an AI-written script does, especially anything that creates, updates or deletes records.
  • Test in a sandbox first. Run AI-written queries and scripts against your sandbox before production.

Keep AI Agents on a Short Leash

AI agents can call the API on their own, run many steps in a row, and retry when something fails. Set them up so a mistake stays small:

  • Start read-only. Give the agent's user only the roles it needs to read data. Add write access only when you have a clear, reviewed reason.
  • Keep a person in the loop for changes. Require a person to review and approve any change before the agent makes it.
  • Don't rely on roles alone. Roles control what a user can do, but the safest agent is one that's only given the tasks and token it needs. Don't connect an agent to an admin user's token.
  • Cap how much it can do. Limit the number of requests or records an agent can touch in one run, and watch it the first few times it runs.
  • Turn it off when you're done. Revoke the agent's token when the project ends.
❗️

Never Let an AI Tool Sign or Approve

E-signatures in DataNinja record who approved what. Don't give an AI tool your credentials so it can sign, approve, release or close records for you. If an automation touches GMP records, include it in your computer system validation (CSV) and 21 CFR Part 11 processes, just like any other system.


Quick Checklist

Before you run itYes?
The goal can't be met more simply with a report☐
Tested in a sandbox☐
Uses its own named token from a dedicated integration user☐
That user has only the roles it needs (read-only for AI tools where possible)☐
Token stored in a password manager, not in the script or a prompt☐
Queries select specific fields and use WHERE and LIMIT☐
Retries wait and stop after a few attempts☐
A person reviewed any AI-written query or script☐
A person approves any change before it's written☐
Approvals and e-signatures are left to people☐
Token expiration date noted☐

Getting Help

If your script, integration or AI tool isn't behaving as expected, or you're not sure whether an approach is safe for your site, use the blue chat bubble on this page to reach our Support team. Tell us what you're trying to accomplish, and we'll help you find the best way to do it.