---
title: "Zapier"
description: "使用 webhook 和 REST API 将 Quire 连接到 Zapier。"
image: "https://docs.quirelms.com/og.png"
---

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

# Zapier

<span id="zapier"></span>

Zapier 通过所有集成都使用的 REST API、OAuth 客户端和 webhook 连接 Quire。双方都不需要 Quire 专用代码，因此 Zap 可以执行[API 参考](https://docs.quirelms.com/api/)中提供的任何操作。

## 在 Quire 发生事件时启动 Zap <!--quire:start-a-zap-when-something-happens-in-quire-->

1. 在 Zapier 中选择 **Webhooks by Zapier** 作为触发器，并选择 **Catch Raw Hook** 事件。请选择原始数据，因为签名是根据 Quire 发送的确切字节计算的。复制 Zapier 提供的地址。
2. 在 Quire 中打开 `/admin/webhooks`，选择**添加订阅**，粘贴地址并选择事件，例如 `course_completion.changed`。Quire 会先发送测试事件；Zapier 收到后订阅才会开始。
3. 添加一个 **Code by Zapier** 步骤，按照[开发者指南](/zh-Hans/developer/#webhooks)中的说明，使用订阅密钥验证签名。验证失败时停止 Zap。
4. 解析正文并继续执行所需步骤。

## 从 Zap 操作 Quire <!--quire:act-in-quire-from-a-zap-->

使用 **Webhooks by Zapier** 的 **Custom Request** 操作，或应用步骤中的 **API Request**：

- **URL**：`https://acme.quirelms.com/api/v1/...`，例如使用 `/api/v1/enrolments` 为用户选课。
- **标头**：填写 `Authorization: Bearer qk_live_...`，使用管理员在 `/admin/integrations/api-keys` 为此 Zap 单独创建的密钥；再使用触发器 ID 构建 `Idempotency-Key`，这样 Zapier 重放 Zap 时不会为同一人重复选课。
- **数据**：使用 JSON，格式见 API 参考。

如果要以某个人的身份操作，而非代表组织操作，请在 `/admin/integrations/oauth-clients` 使用 Zapier 的重定向地址注册 OAuth 客户端，并在私有 Zapier 集成中使用该客户端。

## 示例：交易完成后为客户选课 <!--quire:example-enrol-a-customer-when-a-deal-closes-->

1. 触发器：CRM 中的“交易成功”。
2. 自定义请求 `PUT /api/v1/users/ext:{customer id}`，填写用户姓名和电子邮件：如果用户不存在则创建，已存在则更新。
3. 自定义请求 `POST /api/v1/enrolments`，填写用户和课程，并设置 `Idempotency-Key: deal-{deal id}`。

Source: https://docs.quirelms.com/zh-Hans/integrations/zapier/index.mdx
