QR Code 和短連結

本指南會介紹如何使用 WhatsApp Business 管理 API 來建立和管理 QR Code。

顧客可以用手機掃描 QR Code 來快速與您的商家開始對話。而透過 WhatsApp Business 管理 API,您可以建立和存取這類 QR Code 及相關的短連結。

如果您可以使用企業管理平台而無需透過 WhatsApp Business 管理 API 來管理自己的 QR Code,請參閱管理您的 WhatsApp QR Code 一文。

準備工作

您需要準備下列項目:

建立 QR Code

如要建立 QR Code,請向 WhatsApp Business 電話號碼 > 訊息 Qrdls 端點傳送 POST 要求。

在 POST 內文中,加入 prefilled_message 屬性設為訊息文字,以及 generate_qr_image 屬性設為偏好圖像格式(SVGPNG)的物件。

要求範例

curl 'https://graph.facebook.com/v19.0/106540352242922/message_qrdls' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer EAAJB...' \
-d '
{
  "prefilled_message": "Cyber Monday",
  "generate_qr_image": "SVG"
}'

回應範例

{
  "code": "4O4YGZEG3RIVE1",
  "prefilled_message": "Cyber Monday 1",
  "deep_link_url": "https://wa.me/message/4O4YGZEG3RIVE1",
  "qr_image_url": "https://scontent-iad3-2.xx.fbcdn.net/..."
}

取得 QR Code 清單

如要取得包含特定商家電話號碼所有 QR Code 的清單,請向 WhatsApp Business 電話號碼 > 訊息 Qrdls 端點傳送 GET 要求。

要求範例

curl 'https://graph.facebook.com/v19.0/106540352242922/message_qrdls' \
-H 'Authorization: Bearer EAAJB...'

回應範例

{
  "data": [
    {
      "code": "4O4YGZEG3RIVE1",
      "prefilled_message": "Cyber Monday",
      "deep_link_url": "https://wa.me/message/4O4YGZEG3RIVE1"
    },
    {
      "code": "WOMVT6TJ2BP7A1",
      "prefilled_message": "Tell me more about your production workshop",
      "deep_link_url": "https://wa.me/message/WOMVT6TJ2BP7A1"
    }
  ]
}

取得 QR Code

如要取得有關某個特定 QR Code 的資訊,請向 WhatsApp Business 電話號碼 > 訊息 Qrdls 端點傳送 GET 要求,並以路徑參數的形式將 QR Code 編號附加到要求當中。

要求範例

curl 'https://graph.facebook.com/v19.0/106540352242922/message_qrdls/4O4YGZEG3RIVE1' \
-H 'Authorization: Bearer EAAJB...'

回應範例

{
  "data": [
    {
      "code": "4O4YGZEG3RIVE1",
      "prefilled_message": "Cyber Monday",
      "deep_link_url": "https://wa.me/message/4O4YGZEG3RIVE1"
    }
  ]
}

更新 QR Code

如要更新 QR Code,請向 WhatsApp Business 電話號碼 > 訊息 Qrdls 端點傳送 POST 要求。

在 POST 內文中,加入設為要更新之 QR Code 編號的 code 屬性,以及設為新 QR Code 文字的 prefilled_message 屬性。

要求範例

curl 'https://graph.facebook.com/v19.0/106540352242922/message_qrdls' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer EAAJB...' \
-d '
{
    "code": "4O4YGZEG3RIVE1",
    "prefilled_message": "Cyber Tuesday"
}'

回應範例

{
  "code": "4O4YGZEG3RIVE1",
  "prefilled_message": "Cyber Tuesday",
  "deep_link_url": "https://wa.me/message/4O4YGZEG3RIVE1"
}

刪除 QR Code

QR Code 不會自動過期。如要刪除 QR Code,請向 WhatsApp Business 電話號碼 > 訊息 Qrdls 端點傳送 DELETE 要求,並以路徑參數的形式將要停用的 QR Code 編號附加到要求當中。

要求範例

curl -X DELETE 'https://graph.facebook.com/v19.0/106540352242922/message_qrdls/4O4YGZEG3RIVE1' \
-H 'Authorization: Bearer EAAJB...'

回應範例

{
  "success": true
}

參考資料

進一步了解以下主題