Posts tagged with whatsapp

I have been verified as Tech Provider for Whatsapp. I have implemented the embedded signup flow for Whats app and doing the following thing:

  1. Exchange the token with system user access token
  2. Get WABA ID (via Graph API)
  3. Get Phone Number ID (via Graph API)
  4. Register Phone Number (via Graph API)
  5. Subscribing For Webhook Notifications (via Graph API)

All other requests work fine except the last one, subscribing for Webhook Notifications. It gives the following exception:

Unsupported post request. Object with ID '475530585635833' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api 

Has any body experienced the same? Any workaround/solution?

Here is the code:

This is the sequence in which the requests are made:

// 1. Obtain exchanged token const exchangedToken = await this.exchangeFacebookCode(code);console.log("exchangedToken:", exchangedToken); // 2. Obtain WABA ID const wabaId = await this.fetchWABA(exchangedToken); console.log("wabaId:", wabaId); // 3. Obtain Phone Number ID const number = await this.fetchPhoneNumber(exchangedToken, wabaId); console.log("number:", number); // 4. Register Phone Number await this.registerPhoneNumber(exchangedToken, number.id); // 5. Subscribe to Webhook await this.subscribeToWebhook(exchangedToken, wabaId); return { id: number.id, number: number.display_phone_number}; 

These are the method implementation

private async exchangeFacebookCode(code: string): Promise<string> { const appId = "**********"; const appSecret = "**********"; try { const response = await firstValueFrom(this.httpService.get(`https://graph.facebook.com/v12.0/oauth/access_token?client_id=${appId}&client_secret=${appSecret}&code=${code}`));             console.log(JSON.stringify(response.data));             const { access_token: token } = response.data;             return token;         } catch (e) {             console.log("error:", e);             return undefined;         }     }     private async fetchWABA(token: string): Promise<string> {         try {             const observable = this.httpService.get(`https://graph.facebook.com/v21.0/debug_token?input_token=${token}`, {                 headers: {                     "Authorization": `Bearer ${token}`                 }             });             const response = await lastValueFrom(observable);             const { data } = response.data;             console.log("WABA response:", JSON.stringify(response.data));             const { granular_scopes: scopes } = data;             const scope = (scopes as any[]).find(scope => scope.scope === "whatsapp_business_management");             return scope.target_ids[0];         } catch (e) {             console.log("error:", e);             return undefined;         }     }     private async fetchPhoneNumber(token: string, wabaId: string): Promise<any> {         try {             const observable = this.httpService.get(`https://graph.facebook.com/v21.0/${wabaId}/phone_numbers?access_token=${token}`);             const response = await lastValueFrom(observable);             console.log("PhoneNumber ID response:", response.data);             const { data } = response.data;             const phoneNumber = data as any[];             return phoneNumber && phoneNumber.length > 0 && phoneNumber[0];         } catch (e) {             console.log("Error during fetch phone number:", e.response.data);         }     }     private async registerPhoneNumber(token: string, phoneNumberId: string): Promise<void> {         try {             const observable = this.httpService.post(`https://graph.facebook.com/v21.0/${phoneNumberId}/register`, {                 messaging_product: "whatsapp",                 pin: "123456"             }, {                 headers: {                     "Authorization": `Bearer ${token}`,                 }             });             const response = await lastValueFrom(observable);             console.log("Register response:", response.data);         } catch (e) {             console.log("Error during phone registration:", e);         }     }     private async subscribeToWebhook(token: string, wabaId: string): Promise<void> {         try {             const observable = this.httpService.post(`https://graph.facebook.com/v21.0/${wabaId}/subscribed_apps`, {                 headers: {                     "Authorization": `Bearer ${token}`                 }             });             const response = await lastValueFrom(observable);             console.log("Subscription response:", response.data);         } catch (e) {             console.log("Error during webhook subscription:", e.response.data);         }     } 

We are integrating WhatsApp Cloud API for our app through the Business API Gateway. Here's what we have done so far:

Successfully generated a short-lived access token via the Graph API. Used the token, version, and ID for API calls, which worked fine. Meta approved our app review request. However, the issue arises when we attempt to generate a long-lived (or permanent) access token. After making the request, our account gets temporarily blocked or restricted.

Does anyone know why this might be happening or what steps we need to take to avoid the restriction when generating a long-lived access token?

We're following Meta's guidelines for generating access tokens. Short-lived tokens work fine, but the issue is specific to the long-lived token generation. We've made sure all API calls adhere to the required permissions and scopes. Any guidance or insights would be appreciated.

Problem: I’m using the Meta WhatsApp Business API to send template messages. When I try to send the first message using Postman, I get a 200 OK response, but the message is not delivered to the recipient's phone. However, if the user sends me a message first, the API works as expected, and the message is delivered.

Here is the JSON request I'm using:

{   "messaging_product": "whatsapp",   "to": "91790******",   "type": "template",   "template": {     "name": "hello_world",     "language": {       "code": "en_US"     }   } } 

The response I receive is:

{   "messaging_product": "whatsapp",   "contacts": [     {       "input": "91790******",       "wa_id": "91790******"     }   ],   "messages": [     {       "id": "wamid.HBgMOTE3OTA0NjMwMzM3F***dfdffQkI1QzcwNTd**==",       "message_status": "accepted"     }   ] } 

I’ve confirmed that the template (hello_world) is approved and active. The API request returns a 200 OK response, but the message is still not delivered to the recipient unless they initiate the conversation by sending a message first.

Question: Why is the message not being delivered when sending it as the first message? How can I send the first template message without requiring the user to send a message first?

Additional Details: I’m using the Meta WhatsApp Business API. The template is approved, and the recipient's phone number is valid.

Can we create Media template with using Resumable Upload API of Meta, if we have the https url of the media

We wanted the create media template using meta cloud api without using resumable upload api.

eg payload : { "category": "MARKETING", "name": "flig_confim", "language": "en", "allow_category_change": true, "components": [ { "type": "BODY", "text": "This is your flight confirmation for {{1}}-{{2}} on {{3}}", "example": { "body_text": [ [ "Delhi", "Banglore", "20th Monday" ] ] } }, { "type": "FOOTER", "text": "To manage the reservation signin to travel portal" }, { "type": "HEADER", "format": "IMAGE", "example": { "header_handle":"4::YX..." } } ] }

Below is the example to create media template with header_handle info got during resumable api. But we wanted to create media tempate without using resumable api, where user will provide the https url of the image/document and we need to create template using that link instead of header_handle