---
title: "CreateApiKey"
---

> 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: EZGH Cloud organizations and IAM › apiKeys

`POST /v1/organizations/{orgId}/api-keys`

## Authentication

Requires one of the following:

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

## Path parameters

- `CreateApiKey.path.orgId` (string, required)

## Header parameters

- `CreateApiKey.header.idempotency-key` (string, optional)

## Request body

_Required._

- `CreateApiKey.name` (string, required)
- `CreateApiKey.botId` (string, optional)
  - format `uuid`; pattern `^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$`
- `CreateApiKey.expiresInDays` (integer, optional)
  - min 1; max 365

## Example request

```json
{
  "name": "string",
  "botId": "58ed41f0-04bf-402f-9853-7143ef7dd5ce",
  "expiresInDays": 1
}
```

## Code samples

### cURL

```curl
curl --request POST \
  --url https://orgs.ezghcloud.com/v1/organizations/string/api-keys \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "string",
  "botId": "58ed41f0-04bf-402f-9853-7143ef7dd5ce",
  "expiresInDays": 1
}
'
```

### TypeScript

```typescript
const url = 'https://orgs.ezghcloud.com/v1/organizations/string/api-keys';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    name: 'string',
    botId: '58ed41f0-04bf-402f-9853-7143ef7dd5ce',
    expiresInDays: 1
  })
};

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

### Python

```python
import requests

url = "https://orgs.ezghcloud.com/v1/organizations/string/api-keys"

payload = {
    "name": "string",
    "botId": "58ed41f0-04bf-402f-9853-7143ef7dd5ce",
    "expiresInDays": 1
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 201

Success

#### Example

```json
{
  "apiKey": {
    "id": "string",
    "organizationId": "string",
    "name": "string",
    "prefix": "string",
    "owner": {
      "type": "user",
      "id": "string"
    },
    "createdBy": "string",
    "createdAt": "string",
    "lastUsedAt": "string",
    "expiresAt": "string"
  },
  "token": "string"
}
```

- `CreateApiKey.response.201.apiKey` (object, required)
  - `CreateApiKey.response.201.apiKey.id` (string, required)
  - `CreateApiKey.response.201.apiKey.organizationId` (string, required)
  - `CreateApiKey.response.201.apiKey.name` (string, required)
  - `CreateApiKey.response.201.apiKey.prefix` (string, required)
  - `CreateApiKey.response.201.apiKey.owner` (object, required)
    - `CreateApiKey.response.201.apiKey.owner.type` (string, required)
      - one of `"user"`, `"bot"`
    - `CreateApiKey.response.201.apiKey.owner.id` (string, required)
  - `CreateApiKey.response.201.apiKey.createdBy` (string, required)
  - `CreateApiKey.response.201.apiKey.createdAt` (string, required)
  - `CreateApiKey.response.201.apiKey.lastUsedAt` (any of, required)
    - any of: `string`, `null`
  - `CreateApiKey.response.201.apiKey.expiresAt` (any of, required)
    - any of: `string`, `null`
- `CreateApiKey.response.201.token` (string, required)

### 400

InvalidRequest

#### Example

```json
{
  "error": {
    "code": "invalid_request",
    "message": "string",
    "issues": [
      {
        "path": "string",
        "message": "string"
      }
    ]
  }
}
```

- `CreateApiKey.response.400.error` (object, required)
  - `CreateApiKey.response.400.error.code` (string, required)
    - one of `"invalid_request"`
  - `CreateApiKey.response.400.error.message` (string, required)
  - `CreateApiKey.response.400.error.issues` (array<object>, optional)
    - `CreateApiKey.response.400.error.issues.path` (string, required)
    - `CreateApiKey.response.400.error.issues.message` (string, required)

### 401

Unauthenticated

#### Example

```json
{
  "error": {
    "code": "unauthenticated",
    "message": "string"
  }
}
```

- `CreateApiKey.response.401.error` (object, required)
  - `CreateApiKey.response.401.error.code` (string, required)
    - one of `"unauthenticated"`
  - `CreateApiKey.response.401.error.message` (string, required)

### 403

Forbidden | AccessDenied | ForbiddenOrigin

#### Example

```json
{
  "error": {
    "code": "forbidden",
    "message": "string"
  }
}
```

Any of:

- [ForbiddenEncoded](/orgs-api/schemas/ForbiddenEncoded/)
- [AccessDeniedEncoded](/orgs-api/schemas/AccessDeniedEncoded/)
- [ForbiddenOriginEncoded](/orgs-api/schemas/ForbiddenOriginEncoded/)

### 404

NotFound

#### Example

```json
{
  "error": {
    "code": "not_found",
    "message": "string"
  }
}
```

- `CreateApiKey.response.404.error` (object, required)
  - `CreateApiKey.response.404.error.code` (string, required)
    - one of `"not_found"`
  - `CreateApiKey.response.404.error.message` (string, required)

### 409

IdempotencyConflict | IdempotencyInProgress

#### Example

```json
{
  "error": {
    "code": "idempotency_conflict",
    "message": "string"
  }
}
```

Any of:

- [IdempotencyConflictEncoded](/orgs-api/schemas/IdempotencyConflictEncoded/)
- [IdempotencyInProgressEncoded](/orgs-api/schemas/IdempotencyInProgressEncoded/)

### 429

TooManyRequests

#### Example

```json
{
  "error": {
    "code": "too_many_requests",
    "message": "string"
  }
}
```

- `CreateApiKey.response.429.error` (object, required)
  - `CreateApiKey.response.429.error.code` (string, required)
    - one of `"too_many_requests"`
  - `CreateApiKey.response.429.error.message` (string, required)

### 500

InternalError

#### Example

```json
{
  "error": {
    "code": "internal_error",
    "message": "string"
  }
}
```

- `CreateApiKey.response.500.error` (object, required)
  - `CreateApiKey.response.500.error.code` (string, required)
    - one of `"internal_error"`
  - `CreateApiKey.response.500.error.message` (string, required)

### 503

Unavailable

#### Example

```json
{
  "error": {
    "code": "unavailable",
    "message": "string"
  }
}
```

- `CreateApiKey.response.503.error` (object, required)
  - `CreateApiKey.response.503.error.code` (string, required)
    - one of `"unavailable"`
  - `CreateApiKey.response.503.error.message` (string, required)


Source: https://docs.ezghcloud.com/orgs-api/apiKeys/CreateApiKey/index.md
