擷取電話號碼

使用 WhatsApp Business Management API 擷取商家已註冊於其 WhatsApp Business 帳號的電話號碼。

準備工作

必備項目:

  • 您要擷取之商家電話號碼的 WhatsApp Business 帳號編號
  • 連結至 WhatsApp Business 帳號的系統用戶存取權杖
  • whatsapp_business_management 權限

限制

  • 此 API 只能擷取已註冊的電話號碼。不得使用此 API 來新增、更新或刪除電話號碼。

取得所有電話號碼

若要取得與 WhatsApp Business 帳號相關聯的所有電話號碼清單,請傳送 GET 要求至 WhatsApp Business 帳號 > 電話號碼端點。

此外,您可以根據用戶完成內嵌註冊設置的時間,透過 last_onboarded_time 對電話號碼進行遞增或遞減排序。若未指定,則預設的順序為遞減。

要求範例

採用方便閱讀的格式。
curl -X GET "https://graph.facebook.com/v19.0/{whatsapp-business-account-id}/phone_numbers
      ?access_token={system-user-access-token}"

成功時,系統會傳回 JSON 物件,其中包含與商家相關聯的所有商家名稱、電話號碼、電話號碼編號和品質評分清單。結果會依照內嵌註冊完成日期遞減排序,最近設置的項目排在最前面。

{
  "data": [
    {
      "verified_name": "Jasper's Market",
      "display_phone_number": "+1 631-555-5555",
      "id": "1906385232743451",
      "quality_rating": "GREEN"
      
    },
    {
      "verified_name": "Jasper's Ice Cream",
      "display_phone_number": "+1 631-555-5556",
      "id": "1913623884432103",
      "quality_rating": "NA"
    }
  ]
}

要求範例

採用方便閱讀的格式。
curl -X GET "https://graph.facebook.com/v19.0/{whatsapp-business-account-id}/phone_numbers
      ?access_token={system-user-access-token}]&sort=['last_onboarded_time_ascending']"

成功時,系統會傳回 JSON 物件,其中包含與商家相關聯的所有商家名稱、電話號碼、電話號碼編號和品質評分清單。系統會根據用戶完成內嵌註冊的時間遞增排序,最近設置的項目排在最後面。

{
  "data": [
   {
      "verified_name": "Jasper's Ice Cream",
      "display_phone_number": "+1 631-555-5556",
      "id": "1913623884432103",
      "quality_rating": "NA"
    },
    {
      "verified_name": "Jasper's Market",
      "display_phone_number": "+1 631-555-5555",
      "id": "1906385232743451",
      "quality_rating": "GREEN"     
    }   
  ]
}

篩選電話號碼

您可以查詢電話號碼,並根據其 account_mode 進行篩選。此篩選選項目前還在測試版模式下進行測試,並非所有開發人員都能存取。

參數

名稱說明

field

值:account_mode

operator

值:EQUAL

value

值:SANDBOXLIVE

要求範例

curl -i -X GET "https://graph.facebook.com/v19.0/{whatsapp-business-account-ID}/phone_numbers?filtering=[{"field":"account_mode","operator":"EQUAL","value":"SANDBOX"}]&access_token=access-token"

回應範例

{
  "data": [
    {
      "id": "1972385232742141",    
      "display_phone_number": "+1 631-555-1111",
      "verified_name": "John’s Cake Shop",
      "quality_rating": "UNKNOWN",
    }
  ],
  "paging": {
	"cursors": {
		"before": "abcdefghij",
		"after": "klmnopqr"
	}
   }
}

取得單一電話號碼

若要取得電話號碼的相關資訊,請傳送 GET 要求至 WhatsApp Business 電話號碼端點:

要求語法

GET https://graph.facebook.com/<API_VERSION>/<PHONE_NUMBER_ID>

要求範例

curl \
'https://graph.facebook.com/v15.0/105954558954427/' \
-H 'Authorization: Bearer EAAFl...'

成功時,系統會傳回 JSON 物件,其中包含所查詢之電話號碼的商業名稱、電話號碼、電話號碼編號和品質評分。

{
  "code_verification_status" : "VERIFIED",
  "display_phone_number" : "15555555555",
  "id" : "105954558954427",
  "quality_rating" : "GREEN",
  "verified_name" : "Support Number"
}

取得顯示名稱狀態(測試版)

包含 fields=name_status 做為查詢字串參數,可取得與特定電話號碼相關聯的顯示名稱狀態。此欄位目前處於測試階段,並非所有開發人員都能使用。

要求範例

curl \
'https://graph.facebook.com/v15.0/105954558954427?fields=name_status' \
-H 'Authorization: Bearer EAAFl...'

回應範例

{
  "id" : "105954558954427",
  "name_status" : "AVAILABLE_WITHOUT_REVIEW"
}

name_status 值可能是下列其中一項:

  • APPROVED:名稱已獲得批准。您可以立即下載憑證。
  • AVAILABLE_WITHOUT_REVIEW:該電話的憑證可供使用,而顯示名稱不需審核即可使用。
  • DECLINED:名稱未獲得批准。您無法下載憑證。
  • EXPIRED:您的憑證已過期,無法再下載。
  • PENDING_REVIEW:您的名稱要求正在審核中。您無法下載憑證。
  • NONE:沒有可用的憑證。

請注意,憑證的有效期為 7 天。

瞭解詳情

如需各欄位所有可能值的清單,請參閱電話號碼欄位的圖形 API 參考資料。