---
url: /reference/functions/events/webhook-url.md
---

# 管理 URLs

Web trigger 运行时 API 可以编程方式管理 Webhook URL。

导入：

```typescript
import { webhook } from "@pc-nexus/event";
```

内置方法：

## getUrl

根据指定的 Web trigger key，获取对应 Webhook URL。

### 函数签名

```typescript
function getUrl(webTriggerKey: string, options?: WebhookGetUrlOptions): Promise<string>

export interface WebhookGetUrlOptions {
    forceCreate?: boolean;
}
```

### 参数

`WebhookGetUrlOptions` 类型定义：

### 返回值

返回 Webhook URL，通过 `Promise<string>` 返回

```javascript
// 返回值示例
"https://4abd2038-a42c-49a1-b98c-ae04e29bf57a.webhook.pingcodex.com/x1/webhookId1"
```

### 示例

```typescript
await webhook.getUrl("example-web-trigger-key");
```

## queryUrls

获取指定 Web trigger key 下的所有 Webhook URL，若未指定则返回当前应用的所有有效 Webhook URL。

### 函数签名

```typescript
function queryUrls(webTriggerKey?: string): Promise<WebhookQueryUrlResult[]> 

export interface WebhookQueryUrlResult {
    webTriggerKey: string;
    url: string;
}

```

### 参数

### 返回值

返回值为查询到的 Webhook URL ，以数组的形式返回，返回值类型为 `Promise<WebhookQueryUrlResult[]>`

`WebhookQueryUrlResult ` 类型说明

```javascript
// 返回值示例
[
  {
    "webTriggerKey": "example-web-trigger-key",
    "url": "http://4abd2038-a42c-49a1-b98c-ae04e29bf57a.webhook.pingcodex.com/x1/webhookId1"
  },
  {
    "webTriggerKey": "example-web-trigger-key",
    "url": "http://4abd2038-a42c-49a1-b98c-ae04e29bf57a.webhook.pingcodex.com/x1/webhookId2"
  }
]
```

### 示例

```typescript
await webhook.queryUrls("example-web-trigger-key"); // 返回指定 Webhook URL

await webhook.queryUrls(); // 返回应用所有的有效 Webhook URL
```

## deleteUrl

删除指定的 Webhook URL

### 函数签名

```typescript
function deleteUrl(webhookUrl: string): Promise<void>
```

### 参数

|名称|描述|
|---|---|
|`webhookUrl`|要删除的 Webhook URL|

### 返回值

空

### 示例

```typescript
await webhook.deleteUrl("http://4abd2038-a42c-49a1-b98c-ae04e29bf57a.webhook.pingcodex.com/x1/xxxx");
```
