Skip to main content

REST API Access

Enterprise

Synopsis​

Exposes DataStream's management operations over a versioned REST API, so resources can be created and managed programmatically instead of through the web interface. A request authenticates with either of two credentials: an API token that you create and govern from the web interface, or a PowerShell sign-in session from the VirtualMetric PowerShell module or Cloud Shell.

The web interface has two surfaces for the API:

  • API Tokens — a tab under Organization > Settings where you generate, manage, regenerate, and delete the tokens that authenticate API requests. Covered in the sections below.
  • Show template — a drawer on the Create screens of most resources, with a Template tab (the resource as a Bicep template) and an API request tab that renders a ready-to-run command (PowerShell or Bash) calling the public API (/api/v1) to create the same resource. See Show Template.

The API is served under the base path /api/v1. The full, interactive endpoint reference is published as a Swagger document — see API Reference.

Authentication​

Every API request authenticates with a bearer token in the Authorization header:

Authorization: Bearer <token>

The token is one of two kinds:

  • An API token carries the permissions of the single role assigned to it when it was created. The API enforces that role on every request.
  • A PowerShell sign-in session acts as the user who approved it: their role, their access to tenants and their email on every audit row apply, exactly as in the web interface. It works in one tenant at a time, and is created by Connect-VMetric or by opening Cloud Shell. See PowerShell.

Either way, an operation succeeds only if the credential's role grants the required permission. The API returns 401 Unauthorized when the token is missing, unrecognized, or expired.

An API token acts as no user. When it acknowledges or resolves an alert, the alert names it API Token: <name>, as the audit log does. See Alerts.

Both kinds share the same plan gate: a tenant without REST API access refuses API tokens and PowerShell sign-ins alike.

To obtain a token, generate one from the API Tokens tab. The full token value is shown only once, at creation time; afterward only a masked form is available.

warning

Treat API tokens as secrets. Anyone holding a token can call the API with that token's role permissions until the token expires or is deleted. Store tokens in a secure location and regenerate them if you suspect exposure.

API Tokens​

An API token is a credential that authenticates REST API requests. Each token has a name, an optional description, an assigned role that determines its permissions, and an optional time limit after which it stops working.

Accessing API Tokens​

To open the API token management interface:

  1. Click the hamburger menu in the top left corner.
  2. Select Organization > Settings.
  3. Open the API Tokens tab.

API Tokens Table​

The table lists every API token in the current organization:

  • Token Name — Human-readable identifier. Click to open the token detail drawer.
  • Description — Optional free-text note.
  • Token — The masked token value. Tokens are hidden by default; clicking the show icon reveals the token value.
  • Time Limit — The expiration date, or Indefinite when no time limit is set.
  • Status — Active or Expired. A token with a time limit moves to Expired automatically once that time is reached.

Controls​

Above the table, the Search field filters tokens by name, and the Generate New Token button opens the creation wizard. Pagination controls at the bottom navigate between pages.

Actions Menu​

On the right side of each row, the actions menu provides:

  • Manage API token — Opens the token detail page.
  • Delete API token — Prompts for confirmation; see Regenerate and Delete.

Create an API Token​

Click Generate New Token to open the four-step wizard.

Token Settings

  • Token name — Required. Between 3 and 128 characters.
  • Description — Optional free-text note (up to 500 characters).

Token Configuration

  • API Key expiration — Optional. Leave Set expiration unchecked to create a token that never expires. When checked, the checkbox label changes to Set API token time limit and an API token expiration field appears — choose a preset (8 hours, 24 hours, 1 week, 1 month) or a custom date and time. After the expiration date, the token is disabled.
  • Assign role — Required. Select one role from the existing custom roles or the pre-defined API roles. The token inherits this role's permissions.
note

You can assign only a role whose permissions you already hold. The check compares permission sets rather than role names, so your own role — and any pre-defined API role whose permissions you hold in full — is a valid choice, with the exception of Owner noted below, while a role carrying a permission you lack is refused with 403 API_TOKEN_ROLE_NOT_GRANTABLE. Working in a managed tenant as an MSSP user, you can assign that tenant's roles provided you hold MSSP_SWITCH in your own organization.

The Owner role cannot be assigned to an API token.

Review and Create

Review the summary of the preceding steps — Token Name, Description, Token Time Limit, and Assign Role. Use Back to return to an earlier step, or click Create token to generate the token.

Save Token

The token is created and displayed. Use the reveal icon to show the value, the copy control to copy it, or Download token to save it to a file.

warning

The full token value is shown only on this step. You will not be able to see or retrieve it again later. Copy or download it before leaving the page.

API Token Details​

Click a token's Token Name in the table, then Manage API Token in the drawer, to open the detail page. It has three tabs.

General Overview

  • Name and Description — Editable. Click Manage token details to modify.
  • An information panel shows the read-only Created and Last updated timestamps.

Token Configuration

  • Token Time Limit — Read-only. The expiration set at creation cannot be changed from this page.
  • Assigned Role — Editable. Click Manage token configuration to assign a different role. The same restriction applies as at creation: you can select only a role whose permissions you already hold.
  • Regenerate API token — Invalidates the current token value and issues a new one. The link appears only after clicking Manage token configuration to enter edit mode; see Regenerate and Delete.

Activity Logs

An audit trail of actions performed on this token, with the columns Date, User, User IP, Object Type, Object, Action, and Action Description. A Search field and a Timeframe filter (Last 24 hours, Last 7 days, Last 30 days, Last 90 days, All time) narrow the list. This is the same audit model used across the platform — see Audit Logs.

Regenerate and Delete​

Regenerate — On the Token Configuration tab, click Manage token configuration to enter edit mode, then click Regenerate API token. A confirmation modal appears. On confirmation, the existing token value is permanently invalidated and a new value is issued, shown only once with the same copy and download options as creation. Any application using the old value loses access until it is updated with the new token.

Delete — Select Delete API token from the table row actions, or Delete token from the detail page actions, and confirm. Deletion is permanent, and any service still using the token immediately loses access.

warning

Both Regenerate and Delete break any integration currently using the token. Update every application that relies on a token before regenerating or deleting it.

Show Template​

The Template and API request drawer shows the resource you are creating as a Bicep template, and the equivalent REST API request. It appears on the Review step of the Create flow for the following resources:

  • Directors and Clusters
  • Devices and Agent enrollment templates
  • Targets
  • Datasets and Profiles
  • Advanced Routes
  • Pipelines
  • Vault secrets and provider configurations
  • Library grok patterns, schemas, lookup tables, scripts and samples
  • Alert rules, rule actions and detection rules
  • Enrollment templates
  • Roles (API request tab only)

On the review step, click Show template to open the drawer. It has two tabs.

The Template tab shows the resource as a Bicep template, with Open in Deploy, Download and Copy. It needs the Deployment read permission, and it is not a REST API feature, so it works on every plan. Where templates do not cover a resource (agents, roles, vault provider configurations), the tab says so and the API request tab works as before. See Deploy.

The API request tab displays:

  • The HTTP method and endpoint path for the resource (for example, POST /devices).
  • A PowerShell tab and a Bash tab, each containing a copyable command that reproduces the request, populated with the values from the form. A secret you typed shows as a placeholder named after its field, for example <password>. The detection wizard prints one command per rule.
  • A View API tokens button that opens the API Tokens tab, and a View API docs button that opens the Swagger reference.

Each command starts by setting BASE_URL, already filled in with this host's /api/v1, and API_TOKEN, set to <your API token>: replace it with a token from the API Tokens tab before you run the command. For example, the Bash command to create a device:

BASE_URL="https://datastream.example.com/api/v1"
API_TOKEN="<your API token>"

curl -X POST "$BASE_URL/devices" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "my-device"
}'

The equivalent PowerShell command:

$BASE_URL = "https://datastream.example.com/api/v1"
$API_TOKEN = "<your API token>"

$headers = @{
"Authorization" = "Bearer $API_TOKEN"
}

$body = @'
{
"name": "my-device"
}
'@

Invoke-RestMethod -Method POST -Uri "$BASE_URL/devices" `
-Headers $headers `
-ContentType "application/json" `
-Body $body

The request runs only if the supplied token's role grants the permission the endpoint requires.

On a plan without REST API access, the API request tab shows the upgrade prompt instead of the commands; the Template tab is unaffected.

API Resources​

The Public API v1 registers the following resource groups under /api/v1. Each group supports standard CRUD operations; the full request and response schemas are defined in the Swagger reference.

ResourceBase path
Directors/api/v1/directors
Clusters/api/v1/clusters
Devices/api/v1/devices
Agents/api/v1/agents
Targets/api/v1/targets
Datasets/api/v1/datasets
Profiles/api/v1/profiles
Pipelines, with their children and staging/api/v1/pipelines
Quick Routes/api/v1/quickroutes
Advanced Routes/api/v1/advancedroutes
Library/api/v1/library/{kind}
Content Hub/api/v1/contenthub
Alert rules/api/v1/alert-rules
Alerts/api/v1/alerts
Rule actions/api/v1/rule-actions
Detection rules/api/v1/detections
Enrollment templates/api/v1/enrollment-templates
Deployment resources/api/v1/deployments/resources
Vault/api/v1/vault
Audit/api/v1/audit
Users/api/v1/users
Roles/api/v1/roles
Tenant/api/v1/tenant

Pipelines, clusters, quick routes, the Library, Content Hub, alert rules, rule actions, detection rules and enrollment templates speak the JSON a Bicep template writes for the resource. A read by id answers {id, name, resourceType, properties}, and a create or update takes {name, properties}. A write is validated as a template is, and each route needs the permissions of the console action it stands for. The Library's {kind} is one of grokpatterns, schemas, lookups, scripts, samples, snmpvendors and sensitivedatarules. A pipeline write through the API is committed and merged directly, unless the request sets review: true to leave the commit for a reviewer.

Alert rules need the monitoring.rules feature, detection rules monitoring.detections, and enrollment templates enrollment. Rule actions have no feature gate, as in the console. Alert rules and rule actions also have PUT /{id}/status, which enables or disables them as the console's toggle does.

Targets, directors and agents accept the fields the console sends:

  • Targets — relations (the directors or clusters to publish to; without it a target goes to every director), libraries, proxyOptions and detectionRuleIds.
  • Directors — stage, tokens and tokenEnabled. properties is required and must carry proxy_tls.mode: self-signed, custom or offloaded.
  • Agents — description, tags and credentialIds. On update, a list left out keeps its value.

Deployment resources deploy resources given in that same form as a one-off template: POST /deployments/resources deploys them, POST /deployments/resources/preview shows what the engine would change, and POST /deployments/resources/read reads their current state. The PowerShell module writes through these routes, so that -WhatIf shows the engine's real change.

These routes read what the console's health views, unit tests and Search page read. The PowerShell health, pipeline test and search cmdlets call them.

RouteWhat it doesPermissions
GET /devices/{id}/healthA device's healthSTATS_READ, DEVICE_READ, DIRECTOR_READ, TARGET_READ, PIPELINE_READ
GET /directors/{id}/healthA director's healthSTATS_READ, DIRECTOR_READ, DEVICE_READ, TARGET_READ
GET /targets/{id}/healthA target's healthSTATS_READ, TARGET_READ
GET /pipelines/{id}/testsA pipeline's unit tests, with their last statusPIPELINE_READ
POST /pipelines/{id}/tests/runRuns a pipeline's unit testsPIPELINE_READ
GET /search/sourcesThe sources a search can readLIVEDATA_READ
POST /search/runReads the rows of one sourceLIVEDATA_READ

POST /search/run treats the query as a filter, not a program. The source applies the time range and the filters it can, and the answer's warnings say what of the query was not applied. See PowerShell for what each source applies.

Alerts​

While an alert is Open or Acknowledged, its rule raises no new alert for the same resource. When the rule triggers again, the existing alert counts the repeat instead. So a team that tracks alerts somewhere else, such as in Jira issues, has to resolve them in DataStream too. Otherwise the next trigger on that resource raises no alert. These routes let a script or an automation list, acknowledge and resolve alerts. Each action goes through the same checks as in the console, and writes the same timeline entry and audit row. See Alerts.

The routes need the monitoring.alerts feature. The PowerShell alert cmdlets call them.

RouteWhat it doesPermissions
GET /alertsLists alerts, newest first. Filters: status (open, acknowledged, resolved, or active for open and acknowledged together), severity, resourceType, ruleType, ruleId, resourceId, search (part of the resource's name) and ticketALERT_READ
GET /alerts/{id}One alert, with its acknowledgement and resolution: when, the note, and who actedALERT_READ
PUT /alerts/{id}/acknowledgeAcknowledges an open alert, with an optional note. Any other alert is refused with 409 ALERT_NOT_ELIGIBLEALERT_EDIT
DELETE /alerts/{id}/acknowledgeRemoves the acknowledgement: an acknowledged alert goes back to open. Any other alert is refused with 409 ALERT_NOT_ELIGIBLEALERT_EDIT
PUT /alerts/{id}/resolveResolves an open or acknowledged alert. A note of up to 200 characters is required. An alert already resolved is refused with 409 ALERT_ALREADY_RESOLVEDALERT_EDIT
PUT /alerts/acknowledgeAcknowledges up to 500 alerts, given as ids, with one optional noteALERT_EDIT
PUT /alerts/resolveResolves up to 500 alerts, given as ids, with one required noteALERT_EDIT
  • Several alerts at once. PUT /alerts/acknowledge and PUT /alerts/resolve always answer 200 to a well-formed request, even when some alerts are refused. Each refused alert is listed in failed, with its code. An empty ids is refused with 400.
  • Tickets. Each alert carries tickets: the Jira issue keys, and the Freshservice or Freshdesk ticket ids, that its rule's actions opened or commented on. ticket=OPS-123 finds the alerts behind one, ignoring case. One issue can hold several alerts, when a notification grouped them or a later alert was added to the issue as a comment.
  • Who acted. A PowerShell or Cloud Shell session acts as its user. An API token acts as no user, so the alert names it API Token: <name>, as the audit log does: in by, on the alert's timeline and in the console.

For example, a Jira automation that runs when an issue is closed can resolve the issue's alerts:

set -o pipefail
ids=$(curl -sf "$BASE_URL/alerts?ticket=OPS-123&status=active&itemCount=100" -H "Authorization: Bearer $API_TOKEN" | jq -c '[.items[].id]') || exit 1
[ "$ids" = "[]" ] || curl -sf -X PUT "$BASE_URL/alerts/resolve" -H "Authorization: Bearer $API_TOKEN" -H 'Content-Type: application/json' \
-d '{"ids":'"$ids"',"note":"Closed in Jira OPS-123"}'

The second call is skipped when none of the issue's alerts is still active, because an empty ids is refused.

API Reference​

The complete endpoint reference is published as an interactive Swagger document at /api/v1/swagger/index.html on your DataStream host. It lists every available resource, request and response schema, and the permissions each endpoint requires. The View API docs button in the Show template drawer's API request tab links directly to it.