# Create an API proxy

> A proxy on an existing connection; its app is the connection's. The token is in this answer only. Send an Idempotency-Key to retry safely.

Source: https://docs.stacksync.com/api-reference/api-proxies/create_api_proxy

`POST https://api.stacksync.com/v1/workspaces/{workspace_id}/api-proxy`

- Operation: `create_api_proxy`
- Resource: API proxies
- Access: writes data

## Authentication

- `Authorization: Bearer <key>`: A workspace API key (workspace_…, created by a workspace owner under Workspace settings > Stacksync API) acts with editor rights on that workspace only; a user API key (user_…, created under Profile > Stacksync API) acts as that user in every workspace they belong to. POST, PUT and PATCH requests must send Content-Type: application/json. Every authentication failure answers 403.
- `Content-Type: application/json` on every request with a body.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace_id` | integer | Yes | The workspace. List the ones your key can reach with GET /v1/workspaces. |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `region` | string (besg \| usnv) | Yes | Region of the resource: besg (Europe) or usnv (United States), as GET /v1/regions lists them |

## Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string \| null | No | Makes the create retry-safe for 24 hours: a retry with the same key answers the resource the first call created, with the Idempotent-Replayed: true header, and creates nothing. 1 to 255 visible ASCII characters. The same key with a different request answers 422; while the first call still runs, 409. |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `connection_id` | string (uuid4) | Yes | The connection the proxy calls the app with; its app is the proxy's app |
| `api_proxy_name` | string \| null, 3 to 63 characters, pattern `^[A-Za-z][A-Za-z0-9_\- ]*$` | No | 3 to 63 characters: a letter first, then letters, digits, spaces, _ and -; unique among the API proxies of the workspace in the region; generated when absent |
| `is_shared_with_workspace` | boolean, default false | No |  |
| `api_proxy_resource_id` | string \| null, pattern `^[a-z0-9_]{1,60}$` | No |  |
| `parent_folder_id` | string \| null | No | The folder to create the proxy in, the root when absent |
| `validate_only` | boolean, default false | No | Run every check of the write and answer 204 without writing: a refused write answers the error the write would |

## Returns

### 200 OK

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `connection_id` | string \| null | Yes |  |
| `api_proxy_id` | string | Yes |  |
| `api_proxy_name` | string | Yes |  |
| `api_proxy_resource_id` | string \| null | Yes | Answered by GET /api-proxy/<api_proxy_id>; null in the list, whose core does not select it |
| `app_type` | string | Yes |  |
| `connection_name` | string \| null | Yes |  |
| `is_shared_with_workspace` | boolean | Yes | Every workspace member may use the proxy, not only its creator |
| `max_objects_per_request` | integer \| null | Yes | The workspace plan's limit of objects per proxied request; null in the list |
| `parent_folder_id` | string \| null | Yes | The folder of the proxy; null at the root, and in the list |
| `created_by` | integer | Yes |  |
| `created_time` | string | Yes | HTTP date (RFC 9110), UTC |
| `last_modified_by` | integer | Yes |  |
| `last_modified_time` | string | Yes | HTTP date (RFC 9110), UTC |
| `region` | string (besg \| usnv) | Yes |  |
| `api_proxy_token` | string \| null | Yes |  |

### 204 No Content

No body.

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/api-proxy?region=besg" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "api_proxy_name": "Salesforce Proxy",
  "connection_id": "6f1c2a9e-4b7d-4e3a-9c5f-2d8b1e7a4c60"
}'
```

## Example response (200)

```json
{
  "connection_id": "<connection_id>",
  "api_proxy_id": "<api_proxy_id>",
  "api_proxy_name": "<api_proxy_name>",
  "api_proxy_resource_id": "<api_proxy_resource_id>",
  "app_type": "<app_type>",
  "connection_name": "<connection_name>",
  "is_shared_with_workspace": false,
  "max_objects_per_request": 0,
  "parent_folder_id": "<parent_folder_id>",
  "created_by": 0,
  "created_time": "<created_time>",
  "last_modified_by": 0,
  "last_modified_time": "<last_modified_time>",
  "region": "besg",
  "api_proxy_token": "<api_proxy_token>"
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | Bad Request | `{ "error": string, "msg": string, "field": string \| null }` |
| 403 | Forbidden | `{ "error": string, "msg": string, "field": string \| null }` |
| 409 | Conflict | `{ "error": string, "msg": string, "field": string \| null }` |
| 422 | Unprocessable Content | `{ "error": string, "msg": string, "field": string \| null }` |

## Related

- [API Reference overview](https://docs.stacksync.com/api-reference): base URLs, regions, pagination, idempotency and errors
- [Authentication](https://docs.stacksync.com/api-reference/authentication): API keys and the 403 answers
- OpenAPI document: https://docs.stacksync.com/openapi.json
- [List API proxies](https://docs.stacksync.com/api-reference/api-proxies/list_api_proxies)
- [Get an API proxy](https://docs.stacksync.com/api-reference/api-proxies/get_api_proxy)
- [Update an API proxy](https://docs.stacksync.com/api-reference/api-proxies/update_api_proxy)
- [Delete an API proxy](https://docs.stacksync.com/api-reference/api-proxies/delete_api_proxy)
- [Regenerate an API proxy token](https://docs.stacksync.com/api-reference/api-proxies/regenerate_api_proxy_token)