<span id="获取企业微信扫码连接凭据"></span>

# Get WeCom QR binding credentials

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Obtain credentials for a WeCom QR binding.

```text
POST https://api.moi.matrixorigin.cn/v5/workspaces/{workspace_id}/ingress-connections/wecom-qr
```

<span id="调用前准备"></span>

## Before you call this API

Prepare a personal access token with access to the target workspace and permission for the action. The path workspace must match X-Workspace-ID. Examples use jq. See [common information](objects.md) for variables, objects, and states.

<span id="请求体"></span>

## Request body

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl -X POST "https://api.moi.matrixorigin.cn/v5/workspaces/$WORKSPACE_ID/ingress-connections/wecom-qr" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  --data-binary "$(jq -n --arg AGENT_WORKSPACE_ID "$AGENT_WORKSPACE_ID" --arg AGENT_ID "$AGENT_ID" '
{
  "target": {
    "kind": "agent",
    "workspace_id": $AGENT_WORKSPACE_ID,
    "id": $AGENT_ID
  }
}
')"
```

:::::
:::::{tab-item} Parameters

The first response contains a QR URL, session token, and expiration time. Subsequent requests use the original session_token to query pending/authorized/expired. Sessions last 5 minutes; obey Retry-After on 429 responses. An authorized response returns bot_id/secret for creating a wecom/managed_stream connection. This action does not save a real connection. Handle tokens and secrets only in a protected client, without logging them.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `target` | object | Yes | Agent or team receiving messages. |
| `target.kind` | string | Yes | agent or team. |
| `target.workspace_id` | string | Yes | Target source workspace. Teams belong to the current workspace; agents belong to the current or system workspace. |
| `target.id` | string | Yes | Target ID returned by the catalog. |
| `session_token` | string | No | Omit initially. For subsequent queries, retain the original value returned for the same workspace, account, and target. |

:::::
::::::
:::::::

<span id="成功响应"></span>

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": 0,
  "data": {
    "status": "pending",
    "session_token": "opaque_example",
    "qr_url": "https://work.weixin.qq.com/example",
    "expires_at": "2026-11-11T00:05:00Z"
  }
}
```

:::::
:::::{tab-item} Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | 0 on success. |
| `data` | object | Result object; see common objects for fields. |

:::::
::::::
:::::::

<span id="错误响应"></span>

## Error responses

Handle the HTTP status, business result, and error fields as described in [errors and environments](objects.md#错误与环境). On source or version conflicts, read the current state. Do not automatically replace identities, resources, or request IDs and retry.
