# Import from Opsgenie

`POST https://evohub.io/api/v1/import/opsgenie/apply`

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

Reads the Opsgenie 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 Opsgenie 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.

Creates the schedules, escalation policies and integrations whose source ids
are listed in `schedules`, `policies` and `integrations`, in that order.
Importing an item again does not duplicate it; a schedule imported before only
gains the members who have joined EvoHub since. The answer lists what was
created, updated and skipped, with each new integration's webhook URL.

**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 was done.

Content type: `application/json`

Type: `object`

- `data` (ImportResult, required)
  - `created` (object)
    - `schedules` (array of ImportedItem)
      - `id` (string): The new EvoHub id.
      - `name` (string)
      - `source_id` (string)
      - `opsgenie_id` (string)
    - `policies` (array of ImportedItem)
      - `id` (string): The new EvoHub id.
      - `name` (string)
      - `source_id` (string)
      - `opsgenie_id` (string)
    - `integrations` (array of object)
      - `id` (string)
      - `name` (string)
      - `source_id` (string)
      - `opsgenie_id` (string)
      - `evohub_type` (string)
      - `webhook_url` (string): Where to point the source tool.
  - `updated` (object)
    - `schedules` (array of object)
      - `id` (string)
      - `name` (string)
      - `source_id` (string)
      - `opsgenie_id` (string)
      - `added_members` (array of string)
  - `skipped` (array of object)
    - `kind` (string)
    - `name` (string)
    - `reason` (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 Opsgenie refused the key (`OPSGENIE_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 — Opsgenie could not be read (`OPSGENIE_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 — Opsgenie is rate limiting the key (`OPSGENIE_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/opsgenie/apply' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <TOKEN>' \
  -d '{
  "region": "eu",
  "api_key": "YOUR_OPSGENIE_API_KEY",
  "policies": [
    "P4D5E6F"
  ],
  "team_map": {
    "PTEAM01": "a3f9c2e1-7b4d-4c8a-9e6f-2d1b0c9a8f7e"
  },
  "schedules": [
    "P1A2B3C"
  ],
  "integrations": [
    "P7G8H9I"
  ]
}'
```
