Writing API Scripts with the AI Agent
Use the AI Agent to write ready-to-run scripts against the Axonius REST API v2. When you ask for a script, the agent reads your instance's own API spec, selects the endpoints the task requires, and writes code that matches the exact contracts your instance serves — without inventing endpoints or hardcoding credentials.
How It Works
The API script writer runs as a focused sub-agent, separate from the main conversation. When you request a script, the agent:
- Fetches your instance's API v2 OpenAPI spec from
/api/v2/openapi.json. - Selects the specific endpoints needed for your task.
- Writes a script grounded in those exact contracts — parameters, request bodies, pagination, and authentication as your instance serves them.
- Checks the draft for invented paths or hardcoded credentials, and repairs any it finds.
Because the script writer runs in isolation, it doesn't draw on your chat history. Describe exactly what you need each time you ask for a script.
If your instance can't serve its own spec, the agent falls back to a bundled snapshot of the API v2 spec and says so in the result. In that case, verify the script against your instance's interactive API docs before running it.
Requesting a Script
Describe what the script should do in plain language:
- "Write a Python script that pulls all Windows devices missing CrowdStrike with hostname and last seen date."
- "Give me curl commands to trigger an adapter fetch for the Active Directory connection."
- "Write a PowerShell script that exports the 'Unpatched Critical CVEs' saved query to CSV."
- "Generate a Python script that creates a service account with API access."
You can specify the language and authentication method:
- Language — Python (default, using the
requestslibrary), bash (curl and jq), or PowerShell. - Auth method — Service account API key (default) or OAuth 2.1 client credentials.
What the Agent Returns
After writing the script, the agent shows:
- The script in a code block — copy it as-is.
- The API endpoints the script calls.
- Authentication notes — how to set up credentials as environment variables.
- Assumptions you should confirm before running the script.
- Any caveats, such as endpoints that may differ on your version.
Credentials are never hardcoded in the script. The script reads them from environment variables, which the auth notes explain.
Required Permissions
To run scripts generated by the agent, the service account you use needs API access enabled on its role. For permission details, see the API capability information in your instance's interactive API docs at <your instance URL>/api/v2/docs.
API Documentation
The API docs for your instance are at:
- Swagger UI —
<your instance URL>/api/v2/docs - ReDoc —
<your instance URL>/api/v2/redoc - Raw spec — GET
/api/v2/openapi.json(requires a service account with API access)
Updated about 1 hour ago
