# Create callback rules

Create rules that route provider callback events to workspace resources.

```text
POST $CLOUDSIGMA_API_BASE/workspaces/{workspace_id}/callback-rules
```

## 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.

The example below uses `$CLOUDSIGMA_API_KEY` and `$WORKSPACE_ID`.

## Request example

```bash
curl -X POST "$CLOUDSIGMA_API_BASE/workspaces/$WORKSPACE_ID/callback-rules" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "provider": "github",
    "credential_ref": "credential_01",
    "name": "Issue 回调",
    "target_type": "agent"
  }'
```

## Request body

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `provider` | string | Yes | The callback provider ID. |
| `credential_ref` | string | Yes | Provider credentials reference. |
| `name` | string | Yes | The name of the callback rule. |
| `target_type` | string | Yes | The callback target type. |
| `description` | string | No | Callback rule description. |
| `enabled` | boolean | No | Whether to enable the rule. |
| `priority` | integer | No | Match priority. |
| `match` | object | No | Matching criteria, which can include `resource_kinds`, `event_types`, `event_actions`, and `field_equals`. |
| `target_config` | object | No | Callback target configuration. |
| `stop_after_match` | boolean | No | Whether to stop matching after hitting this rule. |

## Successful response

Returns `201` and a new rule on success.

```json
{"code":0,"data":{"id":"rule_01"}}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `data.id` | string | New callback rule ID. |

## Error response

```json
{"code":2,"message":"invalid callback rule"}
```
