# Call the PerformanceGuard API

> Authenticate to the PerformanceGuard REST API, try requests in Swagger, and set the time interval for data requests.

Source: https://docs.capaone.com/performanceguard/technical-reference/call-the-performanceguard-api/  
Product: PerformanceGuard — a separate CapaSystems product; do not apply this page to any other.

Use the PerformanceGuard REST API to read collected data and manage PerformanceGuard from your own scripts and tools. This page shows you how to find the API documentation, sign in, and set the time interval for data requests.

For an overview of the API, see [PerformanceGuard API](/performanceguard/technical-reference/performanceguard-api/).

:::note[Before you start]
- You need a PerformanceGuard user for the API. We recommend a dedicated user for each integration. See [Manage Users](/performanceguard/administration/manage-users/).
- The user's role decides what the API returns, in the same way as in the web interface. For example, information about individual computers requires the **Detail** or **Admin** role.
- Use HTTPS for the PerformanceGuard web interface, so credentials aren't sent in clear text. See [SSL Server Certificate for HTTPS](/performanceguard/installation/install-performanceguard-server/ssl-server-certificate-for-https/).
:::

## Open the API documentation

The API documentation is built into PerformanceGuard as an interactive Swagger page.

1. In a browser, open the PerformanceGuard web interface and sign in.
2. In the address bar, replace the path with `/swagger`. For example: `https://performanceguard.example.com/swagger`.

The Swagger page lists all endpoints, grouped by area, with their parameters and responses. Because you're signed in, you can select an endpoint and try it directly from the page.

## Send requests from a script

All endpoints are under the `/api` path of the PerformanceGuard web interface address, for example `https://performanceguard.example.com/api/agent`. Requests and responses use JSON unless the endpoint says otherwise.

Authenticate in one of two ways.

### Basic authentication

Send the PerformanceGuard user name and password in a standard HTTP `Authorization: Basic` header with each request. This is the simplest method for scripts.

```powershell
$cred = Get-Credential
Invoke-RestMethod -Uri "https://performanceguard.example.com/api/agent?pattern=PC-01" `
  -Authentication Basic -Credential $cred
```

The `-Authentication` parameter requires PowerShell 7 or newer.

### Sign in with a session

1. Send a `POST` request to `/api/login` with a JSON body that contains `username` and `password`.
2. PerformanceGuard returns a session cookie called `JSESSIONID_MERLIN`. Include that cookie in the following requests.
3. When you're done, send a `DELETE` request to `/api/login` to end the session.

```powershell
$body = @{ username = "api-user"; password = "<password>" } | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri "https://performanceguard.example.com/api/login" `
  -Body $body -ContentType "application/json" -SessionVariable pg

Invoke-RestMethod -Uri "https://performanceguard.example.com/api/agent?pattern=PC-01" -WebSession $pg

Invoke-RestMethod -Method Delete -Uri "https://performanceguard.example.com/api/login" -WebSession $pg
```

If the credentials are wrong, PerformanceGuard returns `401 Unauthorized`.

## Set the time interval

Endpoints that return data for a period take an `interval` query parameter. The value has up to three parts, separated by `|`:

`<period>|<end>|<offset>`

| Part | Required | Description |
|:--|:--|:--|
| `period` | Yes | The length of the interval. See the values in the next table. |
| `end` | No | The end of the interval, as an ISO 8601 date and time with a time zone, or a UTC timestamp in milliseconds. If you leave it out or leave it empty, the interval ends now. |
| `offset` | No | A time zone offset in minutes that's used when PerformanceGuard calculates calendar periods and the current time. |

These are the values you can use for `period`:

| Value | Meaning |
|:--|:--|
| A number, for example `3600000` | The number of milliseconds before the end. `3600000` is one hour. |
| `0` | Two delivery intervals before the end. |
| `XD` followed by a number, for example `XD30` | The number of days before the end. |
| `CH`, `CD`, `CW`, `CM`, `CQ`, `CY` | The current hour, day, week, month, quarter, or year, from its start until the end. |
| `PH`, `PD`, `PW`, `PM`, `PQ`, `PY` | The previous full hour, day, week, month, quarter, or year. |

Examples:

- `interval=86400000`: the last 24 hours.
- `interval=XD7`: the last seven days.
- `interval=PD`: yesterday.
- `interval=86400000|2026-01-31T00:00:00Z`: the 24 hours before midnight UTC on 31 January 2026.

URL-encode the `|` character as `%7C` when you build the address yourself. To check how PerformanceGuard reads an interval value, try it on the `/api/internal/interval` endpoint in Swagger.

## Get data as a spreadsheet

Some endpoints can also return an Excel workbook. In Swagger, those endpoints list `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` as a response type. To get the workbook, send that value in the `Accept` header of the request.
