# Preview an import from PagerDuty

`POST https://evohub.io/api/v1/import/pagerduty/preview`

Part of the [On-Call API](https://docs-dev.evohub.io/oncall.md) reference · operationId `previewPagerDutyImport`.

Reads the PagerDuty account with `api_key` (a read-only key is enough; it is used
for this request only and not stored) in `region` (`us` or `eu`), matches its
users to EvoHub members by email, and works out what would be created.
`team_map` maps PagerDuty team ids to EvoHub teams the caller is in; unmapped
items go to the caller's first team. One import runs per organization at a
time, within 25 seconds.

Nothing is created. Items imported before are marked `already_imported`.

**Permission (API-key scope):** `oncall:settings:write`.

## Authorization

Any one of:

- `bearerAuth` (oncall:settings:write)
- `apiKeyHeader` (oncall:settings:write)

Where:

- `bearerAuth`: HTTP Bearer — An EvoHub API key (`evohub_…`) as a bearer token.
- `apiKeyHeader`: API key in the header `X-API-Key` — An EvoHub API key (`evohub_…`).

## Request body (required)

Content type: `application/json`

Type: `ImportRequest`

Preview reads only `api_key`, `region` and `team_map`. Apply also takes the source ids to import.

- `api_key` (string, required, max length 200): The source account's API key; read access is enough. Not stored.
- `region` (string, required, one of `us`, `eu`)
- `schedules` (array of string)
- `policies` (array of string)
- `integrations` (array of string)
- `team_map` (object): Source team id → EvoHub team id.
  - Other keys: string

## Responses

### 200 — What the account holds and what importing it would do.

Content type: `application/json`

Type: `object`

- `data` (ImportPreview, required)
  - `source` (string, one of `opsgenie`, `pagerduty`)
  - `users` (array of object)
    - `source_id` (string)
    - `opsgenie_id` (string)
    - `email` (string)
    - `name` (string)
    - `evohub_user_id` (string | null): The matching EvoHub member, or null.
  - `teams` (array of object)
    - `source_id` (string)
    - `name` (string)
  - `schedules` (array of object)
    - `source_id` (string)
    - `opsgenie_id` (string)
    - `name` (string)
    - `timezone` (string)
    - `team` (string)
    - `team_source_id` (string)
    - `layers` (array of object)
      - `name` (string)
      - `summary` (string)
      - `participants` (array of string)
    - `already_imported` (boolean)
    - `new_members` (integer): For a schedule imported before: people who would be added now.
    - `warnings` (array of string)
  - `policies` (array of object)
    - `source_id` (string)
    - `opsgenie_id` (string)
    - `name` (string)
    - `team` (string)
    - `team_source_id` (string)
    - `steps` (array of object)
      - `after_minutes` (integer)
      - `targets` (array of string)
    - `already_imported` (boolean)
    - `warnings` (array of string)
  - `integrations` (array of object)
    - `source_id` (string)
    - `opsgenie_id` (string)
    - `name` (string)
    - `source_type` (string)
    - `opsgenie_type` (string)
    - `evohub_type` (string)
    - `policy` (string)
    - `team_source_id` (string)
    - `already_imported` (boolean)
    - `warnings` (array of string)
  - `not_imported` (array of string)
  - `warnings` (array of string)
- `success` (boolean, required, value `true`)

### 400 — The body is not JSON (`INVALID_BODY`); `api_key`, `region` or `team_map` is invalid (`VALIDATION_FAILED`); or PagerDuty refused the key (`PAGERDUTY_UNAUTHORIZED`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 401 — No API key was sent, or it is unknown, revoked or expired (`UNAUTHORIZED`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 403 — The caller lacks the permission (`FORBIDDEN`), or `team_map` names a team the caller is not in (`NOT_IN_TEAM`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 409 — Another import is running for the organization (`IMPORT_IN_PROGRESS`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 429 — Too many requests (`RATE_LIMITED`). Wait `Retry-After` seconds.

Headers:

- `Retry-After` (integer): Seconds to wait.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 500 — Something went wrong on EvoHub's side (`INTERNAL_ERROR`). Retry later.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 502 — PagerDuty could not be read (`PAGERDUTY_UNAVAILABLE`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 503 — PagerDuty is rate limiting the key (`PAGERDUTY_RATE_LIMITED`), or EvoHub members could not be checked (`MEMBER_CHECK_UNAVAILABLE`). Retry shortly.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

## Example request

```bash
curl -X POST 'https://evohub.io/api/v1/import/pagerduty/preview' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <TOKEN>' \
  -d '{
  "region": "eu",
  "api_key": "YOUR_PAGERDUTY_API_KEY"
}'
```
