# Accept data subscription

Accepts a data subscription and specifies the subscription database name in the target workspace.

```text
POST $CLOUDSIGMA_API_BASE/data-share/subscriptions/{id}/subscribe
```

## Before you call this API

Configure the [regional API endpoint and authentication](https://omnifabric.cloudsigma.com/docs/developer/endpoints-and-authentication.html.md), and select the target workspace.

First [query the data subscription list](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/data-subscriptions/list-subscriptions.html.md) to confirm the subscription to be accepted.

Set the operation-specific values used in the request:

- `$SUBSCRIPTION_ID`: The subscription ID to be accepted, taken from the response of [query data subscription list](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/data-subscriptions/list-subscriptions.html.md).

## Request example

```bash
curl -X POST "$CLOUDSIGMA_API_BASE/data-share/subscriptions/$SUBSCRIPTION_ID/subscribe" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "sub_name": "sales_subscription"
  }'
```

## Path parameters

| Parameters | Type | Description |
| --- | --- | --- |
| `id` | integer | A subscription ID greater than `0`. |

## Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `sub_name` | string | Yes | Local subscription name. |

## Successful response

Returns `200` and the updated subscription record on success. Record the target database ID; it represents the subscription database created in the target workspace.

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "id": "201",
    "pub_name": "sales-share",
    "source_database_id": "101",
    "mo_database_name": "sales",
    "table_scope": {
      "mode": "selected",
      "object_ids": ["1001"]
    },
    "target_database_id": "301",
    "obj_display_name": "sales",
    "obj_display_path": "catalog/sales",
    "source_workspace_id": "ws-001",
    "source_workspace_name": "数据工作区",
    "publisher": "user-001",
    "published_at": "2026-08-18T10:00:00Z",
    "status": "subscribed",
    "sub_name": "sales_subscription",
    "subscribed_by": "user-002",
    "created_at": "2026-08-18T10:00:00Z"
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | string | `OK` on success. |
| `msg` | string | `OK` on success. |
| `data.id` | string | Subscription ID. |
| `data.pub_name` | string | Source publication name. |
| `data.source_database_id` | string | Source database ID. |
| `data.mo_database_name` | string | Source database name. |
| `data.table_scope` | object | Publish shared table range. |
| `data.table_scope.mode` | string | Range mode: `all` or `selected`. |
| `data.table_scope.object_ids` | string[] | List of table IDs when the range mode is `selected`. |
| `data.target_database_id` | string | ID of the subscription database in the target workspace; returned after successful acceptance. |
| `data.obj_display_name` | string | The display name of the source database. |
| `data.obj_display_path` | string | The display path of the source database. |
| `data.source_workspace_id` | string | Source workspace ID. |
| `data.source_workspace_name` | string | Source workspace name; returned if there is a value. |
| `data.publisher` | string | Publisher. |
| `data.published_at` | string | Release time. |
| `data.status` | string | Current subscription status. |
| `data.sub_name` | string | The name of the subscription database in the target workspace. |
| `data.subscribed_by` | string | The identity to accept the subscription. |
| `data.created_at` | string | Time to accept subscription. |

`[]` after a type means an array. For example, `string[]` is an array of strings.

## Error response

```json
{
  "code": "ErrAlreadySubscribed",
  "msg": "数据已订阅",
  "data": null
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `ErrParamInvalid`
  - Invalid subscription ID or `sub_name`.
  - Check the path and request body fields.
* - `403`
  - `ErrPermissionDenied`
  - The current identity does not have permission to create subscriptions.
  - Request permission to create data subscriptions.
* - `404`
  - `ErrSubscriptionNotFound`
  - The subscription does not exist or does not belong to the current workspace.
  - Verify subscription ID and workspace.
* - `409`
  - `ErrAlreadySubscribed`
  - The subscription has been accepted.
  - Query the subscription list to avoid repeated submissions.
* - `409`
  - `ErrNameConflict`
  - The target workspace already has a subscription database with the same name.
  - Replace `sub_name` and try again.
* - `503`
  - `ErrServiceUnavailable`
  - Dependent services are temporarily unavailable.
  - Try again later.
* - `500`
  - `ErrServer`
  - The server failed to accept the subscription.
  - Try again later.
```

## Follow-up operations

Use `data.target_database_id` to record the target subscription database; then [Query data subscription list](https://omnifabric.cloudsigma.com/docs/reference/api/ai-studio/resource-center/data-subscriptions/list-subscriptions.html.md) to confirm the subscription status and name.
