> ## Documentation Index
> Fetch the complete documentation index at: https://www.bazhuayu.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 授权一个用户

> 把 App 点对点分享给指定用户，幂等。

## 端点

```
PUT https://api-datahub.bazhuayu.com/v1/data-apps/{app_id}/grants/{username}
```

认证：需要 API Key，且仅 App 作者（发布者本人）可调用；其他人得到 `404`。

向指定用户开放该 App（幂等）。只在 `scope=shared` 时生效；名单内的用户可以查看和运行该 App，并按其价格计费（谁运行谁付费）。接口接受用户名，存储的是用户标识，因为用户名可变，不是标识符。

## 请求

### 路径参数

<ParamField path="app_id" type="string" required>
  App 引用。
</ParamField>

<ParamField path="username" type="string" required>
  被授权用户的用户名。
</ParamField>

### 示例请求

```bash theme={null}
curl -X PUT \
  -H "Authorization: Bearer $BAZHUAYU_API_KEY" \
  "https://api-datahub.bazhuayu.com/v1/data-apps/carol/reviews-query/grants/dave"
```

## 响应

### 200 成功

```json theme={null}
{
  "data": {
    "ok": true
  }
}
```

响应包在 `data` 字段中，其内容如下。

<ResponseField name="ok" type="boolean">
  固定为 `true`。
</ResponseField>

### 错误

| HTTP | `code` | `category` | 说明 |
| - | - | - | - |
| 401 | `unauthorized` | `forbidden` | 缺少或无效的 API Key。 |

错误响应统一为 `{"error": {code, category, message, retryable}}`，见<a href="/docs/zh/datahub/api/reference/introduction#错误" target="_blank" rel="noopener noreferrer">错误</a>。

## 客户端库

Python 与 JavaScript SDK 暂未封装此端点，请直接调用 REST。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.