自定义 Webhook

Postman 的自定义 webhook 集成使您能够自动化您最喜欢的应用程序和服务之间的工作流程,以获取通知、同步文件、收集数据等。它提供具有预定义流程的服务,以便于实施。

您可以使用 Postman 配置自定义 webhook 以发送事件,例如监控结果或团队和特定于集合的活动提要,或备份您的 Postman 集合。

内容

启用静态 IP 支持

如果您的网络位于防火墙后面,您将需要使用静态 IP 地址来启用对自定义域上的自定义 Webhook 的集合备份。

请联系您的 IT 团队,在防火墙中将以下静态 IP 列入许可名单,以启用对 Webhook 的集合备份:

  • 美国东部:3.212.102.200

将此 IP 地址列入白名单后,对自定义 webhook 的调用将能够连接到您的网络并允许 webhook 按预期工作。

配置自定义 webhook

  1. 集成页面上,从集成列表中搜索并选择 Webhook。

    custom_webhook

    集成页面可以选择每种类型的自定义 webhook。如果可用,您可以查看先前为所选集成配置的集成。

    Webhooks 集成选择

  2. 选择webhook 类型旁边的添加集成以配置您的集成。针对您要添加的 webhook 类型执行以下相关部分中的步骤。

创建集成后,除了您的团队创建的其他活动集成之外,您还可以查看刚刚创建的集成:

配置的集成

将 Postman 集合的更新发送到自定义 webhook

要将 Postman 集合的更新发送到自定义 webhook:

  1. Webhooks 集成页面中,在备份集合旁边,选择添加集成
  2. 添加集成页面中:
    • 输入集成的昵称
    • 选择集合下,选择您要为其发送更新的集合。
    • 输入您的 webhook 有效负载将发送到的 webhook URL。
  3. 选择添加集成

示例集合备份架构

以下是用于备份集合 webhook 的架构:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {},
  "id": "http://example.com/example.json",
  "properties": {
    "collection": {
      "id": "/properties/collection",
      "properties": {},
      "type": "object"
    }
  },
  "type": "object"
}

将监控结果发送到自定义 webhook

Postman Monitors 使您能够按计划运行您的收藏,而无需任何人工干预。使用自定义 webhook,您可以通过连接到其他可用服务来使用这些结果。

要将监视器运行结果发送到自定义 webhook:

  1. Webhooks 集成页面中,在发布监控结果旁边,选择添加集成
  2. 添加集成页面中:
    • 输入集成的昵称
    • 选择包含要发送到自定义 Webhook 的监视器的工作区。
    • 选择要发送的监视器。
    • 输入您的 webhook 有效负载将发送到的 webhook URL。
  3. 选择添加集成

您还可以配置高级选项,以在监视器运行完成或发生三个故障以及这些故障成功完成后第一个监视器运行时向您发出警报。

每当您的监视器运行时,结果现在都会发布到您的 webhook。

示例监视器结果架构

以下是监视器运行结果的架构:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {},
  "id": "http://example.com/example.json",
  "properties": {
    "collection_name": {
      "id": "/properties/collection_name",
      "type": "string"
    },
    "collection_uid": {
      "id": "/properties/collection_uid",
      "type": "string"
    },
    "environment_name": {
      "id": "/properties/environment_name",
      "type": "string"
    },
    "environment_uid": {
      "id": "/properties/environment_uid",
      "type": "string"
    },
    "metrics": {
      "id": "/properties/metrics",
      "properties": {
        "errors":
          "id": "/properties/metrics/properties/errors",
          "type": "integer"
        },
        "failedTests": {
          "id": "/properties/metrics/properties/failedTests",
          "type": "integer"
        },
        "passedTests": {
          "id": "/properties/metrics/properties/passedTests",
          "type": "integer"
        },
        "requestCount": {
          "id": "/properties/metrics/properties/requestCount",
          "type": "integer"
        },
        "totalLatency": {
          "id": "/properties/metrics/properties/totalLatency",
          "type": "integer"
        },
        "warnings": {
          "id": "/properties/metrics/properties/warnings",
          "type": "integer"
        }
      },
      "type": "object"
    },
    "monitor_name": {
      "id": "/properties/monitor_name",
      "type": "string"
    },
    "monitor_uid": {
      "id": "/properties/monitor_uid",
      "type": "string"
    },
    "user_id": {
      "id": "/properties/user_id",
      "type": "string"
    },
    "user_name": {
      "id": "/properties/user_name",
      "type": "string"
    }
  },
  "type": "object"
}

将团队活动源发送到自定义 webhook

您可以在活动源中跟踪对收藏和团队内部所做的更改。

要将团队活动源发送到自定义 Webhook:

  1. Webhooks 集成页面中,在发布团队活动旁边,选择添加集成
  2. 添加集成页面中:
    • 输入集成的昵称
    • 输入 webhook URL 以将团队更新发送到此特定 URL。
  3. 选择添加集成

示例团队活动架构

以下是团队活动 webhook 的架构:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {},
  "id": "http://example.com/example.json",
  "properties": {
    "action": {
      "id": "/properties/action",
      "type": "string"
    },
    "collection_name": {
      "id": "/properties/collection_name",
      "type": "string"
    },
    "collection_uid": {
      "id": "/properties/collection_uid",
      "type": "string"
    },
    "message": {
      "id": "/properties/message",
      "type": "string"
    },
    "model": {
      "id": "/properties/model",
      "type": "string"
    },
    "model_name": {
      "id": "/properties/model_name",
      "type": "string"
    },
    "model_uid": {
      "id": "/properties/model_uid",
      "type": "string"
    },
    "user_id": {
      "id": "/properties/user_id",
      "type": "string"
    },
    "user_name": {
      "id": "/properties/user_name",
      "type": "string"
    }
  },
  "type": "object"
}