Is it possible to get whatsapp business account ID and phone number ID using only the access token with an API?
Facebook has the following API -
https://graph.facebook.com/API_VERSION/me?fields=FIELDS&access_token=ACCESS_TOKEN
Does WhatsApp have a similar API where I can get all account information, such as phone number ID and business account ID, by using only the access token and nothing else? I have searched the official documentation and all the APIs I have come across either use the business account ID or the phone number ID to retrieve account information.
I would really appreciate any suggestions provided. Thank you.
Just perhaps someone will find it usefull
try { $response = $fb->get('me?fields=businesses'); $responseData = $response->getDecodedBody(); $phoneNumbers = []; foreach ($responseData['businesses']['data'] as $dataItem) { try { $response = $fb->get($dataItem['id']. '/owned_whatsapp_business_accounts'); $whatsAppBusinessAccounts = $response->getDecodedBody(); foreach ($whatsAppBusinessAccounts['data'] as $whatsAppBusinessAccount) { $response = $fb->get($whatsAppBusinessAccount['id'] . '/phone_numbers'); $phoneNumbersData = $response->getDecodedBody(); foreach ($phoneNumbersData['data'] as $phoneNumber) { $phoneNumber['whatsapp_business_account_id'] = $whatsAppBusinessAccount['id']; $phoneNumber['whatsapp_business_account_name'] = $whatsAppBusinessAccount['name']; $phoneNumber['business_id'] = $dataItem['id']; $phoneNumber['business_name'] = $dataItem['name']; $phoneNumbers[] = $phoneNumber; } } } catch (Exception $e) { // Not all business we can manage } } $tpl->set('phone_numbers', $phoneNumbers); } catch (Exception $e){ // Missing general permission to manage business }Required permissions
'whatsapp_business_management', 'whatsapp_business_messaging', 'business_management'No there is no specific API for individual businesses, At least requires a business account ID, refer to this documentation, there are some APIs to access a single phone number and all phone numbers using business account ID.
For Business Solutions Providers (BSPs), If you are then you have to use Embedded Signup for Business Solution Providers, https://developers.facebook.com/docs/whatsapp/embedded-signup
I'm trying to follow this steps, but gives me Malformed access token
Yes, it is possible.
Take a look here: https://developers.facebook.com/docs/whatsapp/embedded-signup/manage-accounts
use the https://graph.facebook.com/v19.0/debug_token route. Add as input_token your accessToken from the response and as Authorization: Bearer Header also the token and your good to go :)
input_token parameter from responde of signupflow and Authorization: Bearer Header too?
error: "message": "Malformed access token AQCUQBjz97tBWCbdMva;..."
graph.facebook.com/v18.0/debug_token?input_token=AQCUQBjz97tB....
As GET Request with "Authorization: Bearer AQCUQBjz97tB..." in header