コンテンツにスキップ

Webhookオブジェクト

webhookオブジェクトを使用すると、メッセージングエンドポイント経由でWebhookメッセージを変更または作成できます。

{
  "url": (required, string),
  "request_method": (required, string) one of "POST", "PUT", "DELETE", or "GET",
  "request_headers": (optional, Hash) key-value pairs to use as request headers,
  "body": (optional, string or JSON object) payload Braze sends in the webhook request. Pass a JSON object, or a string that contains your payload. If you pass a string that includes JSON, escape quotes and backslashes so the outer messaging request remains valid JSON,
  "message_variation_id": (optional, string) used when providing a campaign_id to specify which message variation this message should be tracked under
}

ベストプラクティスとして、送信者やサーバーが時間の経過とともに変更される可能性があるため、一貫性のある予測可能な動作を確保するために、request_headersフィールドにContent-Typeの明示的な値を指定することをBrazeでは推奨しています。Content-Typeヘッダーの値を指定しない場合、システムはリクエストボディから値を推測します。

JSONボディを持つWebhookオブジェクトの例

bodyフィールドには、送信Webhookのペイロードが格納されます。ペイロードがJSONの場合、JSONオブジェクトとして渡すか、同じJSONを含む文字列として渡すことができます。

以下の2つのWebhookオブジェクトは、いずれも同じペイロードをhttps://example.com/hooks/brazeに送信します。

bodyにJSONオブジェクトを指定する

BrazeはbodyのJSONオブジェクトを受け取り、Webhookの送信前にシリアライズします。

{
  "url": "https://example.com/hooks/braze",
  "request_method": "POST",
  "request_headers": {
    "Content-Type": "application/json"
  },
  "body": {
    "user_id": "12345",
    "event": "purchase",
    "properties": {
      "product": "sneakers",
      "price": 99.99
    }
  }
}

bodyにJSON文字列を指定する

bodyを文字列として指定する場合は、まず内部のJSONを構築し、次にダブルクォートとバックスラッシュをエスケープして、外側のメッセージングリクエストが有効なJSONのままになるようにします。

{
  "user_id": "12345",
  "event": "purchase",
  "properties": {
    "product": "sneakers",
    "price": 99.99
  }
}

このオブジェクトは、bodyの値として以下のエスケープされた文字列になります。

{
  "url": "https://example.com/hooks/braze",
  "request_method": "POST",
  "request_headers": {
    "Content-Type": "application/json"
  },
  "body": "{\"user_id\":\"12345\",\"event\":\"purchase\",\"properties\":{\"product\":\"sneakers\",\"price\":99.99}}"
}
New Stuff!