---
title: "Get a query's status (poll it until it finishes)"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.ezghcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

Path: Trails API › queries

`GET /v1/organizations/{orgId}/queries/{queryId}`

## Authentication

Requires one of the following:

- `apiKey`, http, header `Authorization`
- `oauth`, http, header `Authorization`
- `sessionCookie`, apiKey, in cookie

## Path parameters

- `GetQuery.path.orgId` (string, required) — The organization.
  - format `uuid`
- `GetQuery.path.queryId` (string, required) — The query.
  - format `uuid`

## Code samples

### cURL

```curl
curl --request GET \
  --url https://audit.ezghcloud.com/v1/organizations/497f6eca-6276-4993-bfeb-53cbbbba6f08/queries/497f6eca-6276-4993-bfeb-53cbbbba6f08 \
  --header 'Authorization: Bearer <token>'
```

### TypeScript

```typescript
const url = 'https://audit.ezghcloud.com/v1/organizations/497f6eca-6276-4993-bfeb-53cbbbba6f08/queries/497f6eca-6276-4993-bfeb-53cbbbba6f08';
const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://audit.ezghcloud.com/v1/organizations/497f6eca-6276-4993-bfeb-53cbbbba6f08/queries/497f6eca-6276-4993-bfeb-53cbbbba6f08"

headers = {"Authorization": "Bearer <token>"}

response = requests.get(url, headers=headers)

print(response.text)
```

## Responses

### 200

The query. While it's queued or running, Retry-After suggests when to poll again.

#### Example

```json
{
  "cancelRequested": true,
  "createdAt": "2019-08-24T14:15:22Z",
  "createdBy": "string",
  "createdByIdentity": {},
  "error": {
    "code": "string",
    "message": "string"
  },
  "finishedAt": "string",
  "from": "2019-08-24T14:15:22Z",
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "queuePosition": 0,
  "resultRows": 0,
  "sql": "string",
  "startedAt": "string",
  "stats": {
    "bytesScanned": "5020",
    "elapsedMs": 0,
    "resultRows": 0,
    "rowsScanned": 0
  },
  "status": "string",
  "to": "2019-08-24T14:15:22Z",
  "truncated": true
}
```

- `GetQuery.response.200.cancelRequested` (boolean, required)
- `GetQuery.response.200.createdAt` (string, required)
  - format `date-time`
- `GetQuery.response.200.createdBy` (string, required) — The principal who started it.
- `GetQuery.response.200.from` (string, required)
  - format `date-time`
- `GetQuery.response.200.id` (string, required)
  - format `uuid`
- `GetQuery.response.200.queuePosition` (integer | null, required) — Its place in the organization's line while it's queued (1 is next), in GetQuery's answer; null otherwise, and in lists.
  - format `int64`
- `GetQuery.response.200.sql` (string, required)
- `GetQuery.response.200.status` (string, required) — queued, running, succeeded, failed or cancelled.
- `GetQuery.response.200.to` (string, required)
  - format `date-time`
- `GetQuery.response.200.truncated` (boolean, required)
- `GetQuery.response.200.createdByIdentity` (object | null, optional)
- `GetQuery.response.200.error` (one of, optional)
  - one of: [QueryError](/trails-api/schemas/QueryError/), `null`
- `GetQuery.response.200.finishedAt` (string | null, optional)
- `GetQuery.response.200.resultRows` (integer | null, optional)
  - format `int64`
- `GetQuery.response.200.startedAt` (string | null, optional)
- `GetQuery.response.200.stats` (one of, optional)
  - one of: [QueryStats](/trails-api/schemas/QueryStats/), `null`

### 400

invalid_request, invalid_cursor, invalid_query (with line and column), or lookup_too_broad.

#### Example

```json
{
  "error": {
    "code": "string",
    "column": 0,
    "line": 0,
    "message": "string",
    "quota": {
      "id": "string",
      "inFlight": 0,
      "kind": "allocation",
      "limit": 0,
      "periodStart": "2019-08-24T14:15:22Z",
      "region": "string",
      "resetsAt": "2019-08-24T14:15:22Z",
      "scope": "organization",
      "scopeResourceName": "string",
      "used": 0,
      "window": "string"
    },
    "reason": "string"
  }
}
```

- `GetQuery.response.400.error` (object, required)
  - `GetQuery.response.400.error.code` (string, required)
    - maxLength 64; pattern `^[a-z][a-z0-9_]*$`
  - `GetQuery.response.400.error.message` (string, required)
    - maxLength 1024
  - `GetQuery.response.400.error.column` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.400.error.line` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.400.error.quota` (object, optional) — quota_exceeded: the quota that refused the request. Trails Query's are audit.queries.queriesPerHour and audit.queries.bytesReadPerHour, rate quotas with a PT1H window. Never with Retry-After.
    - `GetQuery.response.400.error.quota.id` (string, required)
    - `GetQuery.response.400.error.quota.kind` (unknown, required)
      - one of `"allocation"`, `"rate"`, `"usage"`, `"concurrency"`
    - `GetQuery.response.400.error.quota.limit` (integer, required)
      - min 0
    - `GetQuery.response.400.error.quota.scope` (unknown, required)
      - one of `"organization"`, `"project"`, `"resource"`
    - `GetQuery.response.400.error.quota.inFlight` (integer, optional)
      - min 0
    - `GetQuery.response.400.error.quota.periodStart` (string, optional)
      - format `date-time`
    - `GetQuery.response.400.error.quota.region` (string, optional)
    - `GetQuery.response.400.error.quota.resetsAt` (string, optional)
      - format `date-time`
    - `GetQuery.response.400.error.quota.scopeResourceName` (string, optional)
    - `GetQuery.response.400.error.quota.used` (integer, optional)
      - min 0
    - `GetQuery.response.400.error.quota.window` (string, optional) — rate only: an ISO 8601 duration, PT1S to PT1H.
  - `GetQuery.response.400.error.reason` (string, optional) — query_failed: the query's own error code.

### 401

unauthenticated: no credential, or one that doesn't check out.

#### Example

```json
{
  "error": {
    "code": "string",
    "column": 0,
    "line": 0,
    "message": "string",
    "quota": {
      "id": "string",
      "inFlight": 0,
      "kind": "allocation",
      "limit": 0,
      "periodStart": "2019-08-24T14:15:22Z",
      "region": "string",
      "resetsAt": "2019-08-24T14:15:22Z",
      "scope": "organization",
      "scopeResourceName": "string",
      "used": 0,
      "window": "string"
    },
    "reason": "string"
  }
}
```

- `GetQuery.response.401.error` (object, required)
  - `GetQuery.response.401.error.code` (string, required)
    - maxLength 64; pattern `^[a-z][a-z0-9_]*$`
  - `GetQuery.response.401.error.message` (string, required)
    - maxLength 1024
  - `GetQuery.response.401.error.column` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.401.error.line` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.401.error.quota` (object, optional) — quota_exceeded: the quota that refused the request. Trails Query's are audit.queries.queriesPerHour and audit.queries.bytesReadPerHour, rate quotas with a PT1H window. Never with Retry-After.
    - `GetQuery.response.401.error.quota.id` (string, required)
    - `GetQuery.response.401.error.quota.kind` (unknown, required)
      - one of `"allocation"`, `"rate"`, `"usage"`, `"concurrency"`
    - `GetQuery.response.401.error.quota.limit` (integer, required)
      - min 0
    - `GetQuery.response.401.error.quota.scope` (unknown, required)
      - one of `"organization"`, `"project"`, `"resource"`
    - `GetQuery.response.401.error.quota.inFlight` (integer, optional)
      - min 0
    - `GetQuery.response.401.error.quota.periodStart` (string, optional)
      - format `date-time`
    - `GetQuery.response.401.error.quota.region` (string, optional)
    - `GetQuery.response.401.error.quota.resetsAt` (string, optional)
      - format `date-time`
    - `GetQuery.response.401.error.quota.scopeResourceName` (string, optional)
    - `GetQuery.response.401.error.quota.used` (integer, optional)
      - min 0
    - `GetQuery.response.401.error.quota.window` (string, optional) — rate only: an ISO 8601 duration, PT1S to PT1H.
  - `GetQuery.response.401.error.reason` (string, optional) — query_failed: the query's own error code.

### 403

access_denied: the caller's policies don't allow the action; forbidden_origin: a cookie-authenticated write from an origin that isn't allowed.

#### Example

```json
{
  "error": {
    "code": "string",
    "column": 0,
    "line": 0,
    "message": "string",
    "quota": {
      "id": "string",
      "inFlight": 0,
      "kind": "allocation",
      "limit": 0,
      "periodStart": "2019-08-24T14:15:22Z",
      "region": "string",
      "resetsAt": "2019-08-24T14:15:22Z",
      "scope": "organization",
      "scopeResourceName": "string",
      "used": 0,
      "window": "string"
    },
    "reason": "string"
  }
}
```

- `GetQuery.response.403.error` (object, required)
  - `GetQuery.response.403.error.code` (string, required)
    - maxLength 64; pattern `^[a-z][a-z0-9_]*$`
  - `GetQuery.response.403.error.message` (string, required)
    - maxLength 1024
  - `GetQuery.response.403.error.column` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.403.error.line` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.403.error.quota` (object, optional) — quota_exceeded: the quota that refused the request. Trails Query's are audit.queries.queriesPerHour and audit.queries.bytesReadPerHour, rate quotas with a PT1H window. Never with Retry-After.
    - `GetQuery.response.403.error.quota.id` (string, required)
    - `GetQuery.response.403.error.quota.kind` (unknown, required)
      - one of `"allocation"`, `"rate"`, `"usage"`, `"concurrency"`
    - `GetQuery.response.403.error.quota.limit` (integer, required)
      - min 0
    - `GetQuery.response.403.error.quota.scope` (unknown, required)
      - one of `"organization"`, `"project"`, `"resource"`
    - `GetQuery.response.403.error.quota.inFlight` (integer, optional)
      - min 0
    - `GetQuery.response.403.error.quota.periodStart` (string, optional)
      - format `date-time`
    - `GetQuery.response.403.error.quota.region` (string, optional)
    - `GetQuery.response.403.error.quota.resetsAt` (string, optional)
      - format `date-time`
    - `GetQuery.response.403.error.quota.scopeResourceName` (string, optional)
    - `GetQuery.response.403.error.quota.used` (integer, optional)
      - min 0
    - `GetQuery.response.403.error.quota.window` (string, optional) — rate only: an ISO 8601 duration, PT1S to PT1H.
  - `GetQuery.response.403.error.reason` (string, optional) — query_failed: the query's own error code.

### 404

not_found: unknown, malformed, or in an organization the caller isn't in.

#### Example

```json
{
  "error": {
    "code": "string",
    "column": 0,
    "line": 0,
    "message": "string",
    "quota": {
      "id": "string",
      "inFlight": 0,
      "kind": "allocation",
      "limit": 0,
      "periodStart": "2019-08-24T14:15:22Z",
      "region": "string",
      "resetsAt": "2019-08-24T14:15:22Z",
      "scope": "organization",
      "scopeResourceName": "string",
      "used": 0,
      "window": "string"
    },
    "reason": "string"
  }
}
```

- `GetQuery.response.404.error` (object, required)
  - `GetQuery.response.404.error.code` (string, required)
    - maxLength 64; pattern `^[a-z][a-z0-9_]*$`
  - `GetQuery.response.404.error.message` (string, required)
    - maxLength 1024
  - `GetQuery.response.404.error.column` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.404.error.line` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.404.error.quota` (object, optional) — quota_exceeded: the quota that refused the request. Trails Query's are audit.queries.queriesPerHour and audit.queries.bytesReadPerHour, rate quotas with a PT1H window. Never with Retry-After.
    - `GetQuery.response.404.error.quota.id` (string, required)
    - `GetQuery.response.404.error.quota.kind` (unknown, required)
      - one of `"allocation"`, `"rate"`, `"usage"`, `"concurrency"`
    - `GetQuery.response.404.error.quota.limit` (integer, required)
      - min 0
    - `GetQuery.response.404.error.quota.scope` (unknown, required)
      - one of `"organization"`, `"project"`, `"resource"`
    - `GetQuery.response.404.error.quota.inFlight` (integer, optional)
      - min 0
    - `GetQuery.response.404.error.quota.periodStart` (string, optional)
      - format `date-time`
    - `GetQuery.response.404.error.quota.region` (string, optional)
    - `GetQuery.response.404.error.quota.resetsAt` (string, optional)
      - format `date-time`
    - `GetQuery.response.404.error.quota.scopeResourceName` (string, optional)
    - `GetQuery.response.404.error.quota.used` (integer, optional)
      - min 0
    - `GetQuery.response.404.error.quota.window` (string, optional) — rate only: an ISO 8601 duration, PT1S to PT1H.
  - `GetQuery.response.404.error.reason` (string, optional) — query_failed: the query's own error code.

### 429

too_many_requests or too_many_queries, with Retry-After; or quota_exceeded (with quota), never with Retry-After.

#### Example

```json
{
  "error": {
    "code": "string",
    "column": 0,
    "line": 0,
    "message": "string",
    "quota": {
      "id": "string",
      "inFlight": 0,
      "kind": "allocation",
      "limit": 0,
      "periodStart": "2019-08-24T14:15:22Z",
      "region": "string",
      "resetsAt": "2019-08-24T14:15:22Z",
      "scope": "organization",
      "scopeResourceName": "string",
      "used": 0,
      "window": "string"
    },
    "reason": "string"
  }
}
```

- `GetQuery.response.429.error` (object, required)
  - `GetQuery.response.429.error.code` (string, required)
    - maxLength 64; pattern `^[a-z][a-z0-9_]*$`
  - `GetQuery.response.429.error.message` (string, required)
    - maxLength 1024
  - `GetQuery.response.429.error.column` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.429.error.line` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.429.error.quota` (object, optional) — quota_exceeded: the quota that refused the request. Trails Query's are audit.queries.queriesPerHour and audit.queries.bytesReadPerHour, rate quotas with a PT1H window. Never with Retry-After.
    - `GetQuery.response.429.error.quota.id` (string, required)
    - `GetQuery.response.429.error.quota.kind` (unknown, required)
      - one of `"allocation"`, `"rate"`, `"usage"`, `"concurrency"`
    - `GetQuery.response.429.error.quota.limit` (integer, required)
      - min 0
    - `GetQuery.response.429.error.quota.scope` (unknown, required)
      - one of `"organization"`, `"project"`, `"resource"`
    - `GetQuery.response.429.error.quota.inFlight` (integer, optional)
      - min 0
    - `GetQuery.response.429.error.quota.periodStart` (string, optional)
      - format `date-time`
    - `GetQuery.response.429.error.quota.region` (string, optional)
    - `GetQuery.response.429.error.quota.resetsAt` (string, optional)
      - format `date-time`
    - `GetQuery.response.429.error.quota.scopeResourceName` (string, optional)
    - `GetQuery.response.429.error.quota.used` (integer, optional)
      - min 0
    - `GetQuery.response.429.error.quota.window` (string, optional) — rate only: an ISO 8601 duration, PT1S to PT1H.
  - `GetQuery.response.429.error.reason` (string, optional) — query_failed: the query's own error code.

### 500

internal_error: a bug; the details are in the logs, under the request ID.

#### Example

```json
{
  "error": {
    "code": "string",
    "column": 0,
    "line": 0,
    "message": "string",
    "quota": {
      "id": "string",
      "inFlight": 0,
      "kind": "allocation",
      "limit": 0,
      "periodStart": "2019-08-24T14:15:22Z",
      "region": "string",
      "resetsAt": "2019-08-24T14:15:22Z",
      "scope": "organization",
      "scopeResourceName": "string",
      "used": 0,
      "window": "string"
    },
    "reason": "string"
  }
}
```

- `GetQuery.response.500.error` (object, required)
  - `GetQuery.response.500.error.code` (string, required)
    - maxLength 64; pattern `^[a-z][a-z0-9_]*$`
  - `GetQuery.response.500.error.message` (string, required)
    - maxLength 1024
  - `GetQuery.response.500.error.column` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.500.error.line` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.500.error.quota` (object, optional) — quota_exceeded: the quota that refused the request. Trails Query's are audit.queries.queriesPerHour and audit.queries.bytesReadPerHour, rate quotas with a PT1H window. Never with Retry-After.
    - `GetQuery.response.500.error.quota.id` (string, required)
    - `GetQuery.response.500.error.quota.kind` (unknown, required)
      - one of `"allocation"`, `"rate"`, `"usage"`, `"concurrency"`
    - `GetQuery.response.500.error.quota.limit` (integer, required)
      - min 0
    - `GetQuery.response.500.error.quota.scope` (unknown, required)
      - one of `"organization"`, `"project"`, `"resource"`
    - `GetQuery.response.500.error.quota.inFlight` (integer, optional)
      - min 0
    - `GetQuery.response.500.error.quota.periodStart` (string, optional)
      - format `date-time`
    - `GetQuery.response.500.error.quota.region` (string, optional)
    - `GetQuery.response.500.error.quota.resetsAt` (string, optional)
      - format `date-time`
    - `GetQuery.response.500.error.quota.scopeResourceName` (string, optional)
    - `GetQuery.response.500.error.quota.used` (integer, optional)
      - min 0
    - `GetQuery.response.500.error.quota.window` (string, optional) — rate only: an ISO 8601 duration, PT1S to PT1H.
  - `GetQuery.response.500.error.reason` (string, optional) — query_failed: the query's own error code.

### 503

unavailable: a dependency the request needs is down. Retry after Retry-After.

#### Example

```json
{
  "error": {
    "code": "string",
    "column": 0,
    "line": 0,
    "message": "string",
    "quota": {
      "id": "string",
      "inFlight": 0,
      "kind": "allocation",
      "limit": 0,
      "periodStart": "2019-08-24T14:15:22Z",
      "region": "string",
      "resetsAt": "2019-08-24T14:15:22Z",
      "scope": "organization",
      "scopeResourceName": "string",
      "used": 0,
      "window": "string"
    },
    "reason": "string"
  }
}
```

- `GetQuery.response.503.error` (object, required)
  - `GetQuery.response.503.error.code` (string, required)
    - maxLength 64; pattern `^[a-z][a-z0-9_]*$`
  - `GetQuery.response.503.error.message` (string, required)
    - maxLength 1024
  - `GetQuery.response.503.error.column` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.503.error.line` (integer, optional) — invalid_query: where the SQL went wrong.
  - `GetQuery.response.503.error.quota` (object, optional) — quota_exceeded: the quota that refused the request. Trails Query's are audit.queries.queriesPerHour and audit.queries.bytesReadPerHour, rate quotas with a PT1H window. Never with Retry-After.
    - `GetQuery.response.503.error.quota.id` (string, required)
    - `GetQuery.response.503.error.quota.kind` (unknown, required)
      - one of `"allocation"`, `"rate"`, `"usage"`, `"concurrency"`
    - `GetQuery.response.503.error.quota.limit` (integer, required)
      - min 0
    - `GetQuery.response.503.error.quota.scope` (unknown, required)
      - one of `"organization"`, `"project"`, `"resource"`
    - `GetQuery.response.503.error.quota.inFlight` (integer, optional)
      - min 0
    - `GetQuery.response.503.error.quota.periodStart` (string, optional)
      - format `date-time`
    - `GetQuery.response.503.error.quota.region` (string, optional)
    - `GetQuery.response.503.error.quota.resetsAt` (string, optional)
      - format `date-time`
    - `GetQuery.response.503.error.quota.scopeResourceName` (string, optional)
    - `GetQuery.response.503.error.quota.used` (integer, optional)
      - min 0
    - `GetQuery.response.503.error.quota.window` (string, optional) — rate only: an ISO 8601 duration, PT1S to PT1H.
  - `GetQuery.response.503.error.reason` (string, optional) — query_failed: the query's own error code.


Source: https://docs.ezghcloud.com/trails-api/queries/GetQuery/index.md
