Back

WhatsApp API Essential Guide

Aug 1, 20246 minute read

What type of API does WhatsApp provide?

WhatsApp primarily uses a REST API for its business integration capabilities.

Type of API

  • WhatsApp uses a REST API for its WhatsApp Business API.

How It Works

  • The API follows REST principles, using HTTP methods like GET, POST, etc. to interact with WhatsApp resources.

  • Responses are typically returned in JSON format.

  • Authentication is required to use the API, usually via access tokens.

Considerations

  • While the core API is REST-based, WhatsApp may use other protocols internally or for specific features.

Does the WhatsApp API have webhooks?

Yes, the official WhatsApp API does have webhooks. Here are the key points about WhatsApp API webhooks:

Webhook Availability

The WhatsApp Business API supports webhooks for various events.

Types of Events

You can subscribe to the following types of webhook events:

  1. Incoming messages (message:in:new)

    • Notified when a new message is sent by users or groups to your WhatsApp number.
  2. Outgoing messages (message:out:new)

    • Notified when an outbound message is delivered from your WhatsApp number to other users.
  3. Message status updates (message:out:ack)

    • Notified when an outbound message status changes (e.g., received or read by the user).
  4. Failed message deliveries (message:out:failed)

    • Notified when a message delivery fails (e.g., max retries exceeded, invalid media, or target phone number not found).
  5. Group updates (group:update)

    • Notified when there are changes in a group, such as subject updates, participant additions/removals, or permission changes.
  6. Channel messages (channel:in)

    • Notified when a new message is received on any channel you are following.

Key Considerations

  • There is no limit to the number of webhook events you can receive.
  • The system can notify your webhook endpoint of up to 5 messages per second.
  • Webhook events are typically delivered within 500-1000 milliseconds for text messages, and 1-10 seconds for multimedia messages.
  • In case of notification failures, the system will retry up to 50 times using an incremental backoff strategy.
  • You can manage webhooks through the API.

Best Practices

  1. Ensure your webhook endpoint can handle the expected volume of events.
  2. Implement proper error handling and logging for webhook events.
  3. Use HTTPS for secure communication between WhatsApp and your server.
  4. Process webhook events asynchronously to avoid blocking your server.

By utilizing these webhooks, you can build real-time integrations and automate responses based on various WhatsApp events, enabling you to create more interactive and responsive WhatsApp-based applications.

Rate Limits and other limitations

Based on the search results, here are the key points about the API rate limits for the WhatsApp Business API:

Messaging Limits

  • WhatsApp API uses a tier system for messaging limits:

    • Tier 1: 1,000 unique customers in a rolling 24-hour period
    • Tier 2: 10,000 unique customers in a rolling 24-hour period
    • Tier 3: 100,000 unique customers in a rolling 24-hour period
  • All businesses start at Tier 1 when registering their phone number

  • Businesses can upgrade to higher tiers based on:

    • Maintaining a good quality rating
    • Reaching a cumulative number of users messaged within a 7-day period

Throughput Limits

  • There are separate limits for messaging throughput, measured in Messages per Second (MPS):
    • Default: 10 MPS for text messages, 1.5 MPS for media messages
    • Can be increased up to 50 MPS upon request and approval

Other Considerations

  • Businesses can respond to customers for free within a 24-hour window
  • After 24 hours, there's a fixed fee for each message sent
  • Message pricing varies by region and volume of messages sent
  • There may be additional rate limiting for sending too many messages to a single user in a short period

Best Practices

  • Maintain a high quality rating to increase chances of tier upgrades
  • For high-volume messaging campaigns, contact WhatsApp support for guidance
  • Be aware of both daily messaging limits and throughput limits when designing your messaging strategy

It's important to note that these limits and policies may change over time, so it's always best to consult the official WhatsApp Business API documentation for the most up-to-date information.

Latest API Version

Here's a summary of the most recent version of the WhatsApp API based on the search results:

Most Recent Version

The most recent version of the WhatsApp API is the WhatsApp Cloud API, which was released in May 2022. This is different from the older WhatsApp Business API.

Key Points

  1. The WhatsApp Cloud API is hosted directly by Meta (formerly Facebook).

  2. It offers similar functionality to the WhatsApp Business API but with some key differences:

    • It's more accessible and cost-effective.
    • There are no fees for access or setup.
    • It offers direct integration and is easier to set up.
  3. The latest version of the WhatsApp On-Premises API client (which is different from the Cloud API) is v2.57.2, introduced on July 09, 2024.

Features of WhatsApp Cloud API

  1. Scalable and secure communication.
  2. Supports the same message types as WhatsApp Business API.
  3. Allows businesses to connect their WhatsApp Business account to other tools and workflows.

How to Get Started

To use the WhatsApp Cloud API, businesses need to:

  1. Create a WhatsApp Business Account (WABA).
  2. Connect a phone number to it via Meta's platform.
  3. Sign up for a Facebook Developer Account.
  4. Set up an app and follow the provided steps to connect and verify a phone number.

Pricing

The WhatsApp Cloud API is free to access and set up. Businesses only pay for the messages they send according to WhatsApp's conversation-based pricing model. The first 1,000 conversations each month are free.

In summary, the WhatsApp Cloud API represents the most recent and accessible version of WhatsApp's API for businesses, offering a cloud-hosted solution with easier setup and integration compared to the older WhatsApp Business API.

How to get a WhatsApp developer account and API Keys?

To get a developer account for WhatsApp and create an API integration, you need to follow these steps:

Create a Facebook Account and Meta Developer Account

  1. If you don't already have one, create a Facebook account.

  2. Create a Meta Developer account by visiting the Meta for Developers website and selecting "Get Started".

  3. Complete the registration process, including verifying your phone number and email address.

Create a WhatsApp Application in Meta

  1. Log in to your Meta Developer account and go to the "My Apps" section.

  2. Click on "Create App" and select "Business" as the app type.

  3. Provide a display name for your application and link it to your business account if applicable.

  4. Select an existing Meta Business Account or create a new one if needed.

Set Up WhatsApp Cloud API

  1. In your newly created app, add the WhatsApp product.

  2. This will create a test WhatsApp Business Account and a test business phone number for you.

  3. You'll receive a temporary access token, Phone Number ID, and WhatsApp Business Account ID.

Obtain a Permanent Access Token

  1. To use the API beyond the 24-hour temporary token, you need to generate a permanent access token.

  2. Add a System User to your business account with Admin role.

  3. Generate a permanent access token for this System User.

What can you do with the WhatsApp API?

Here are the key data models you can interact with using the WhatsApp API, along with what is possible for each:

Contact Information

  • Retrieve contact details like name, phone number, profile picture
  • Update contact information
  • Add new contacts
  • Delete contacts

Messages

  • Send text messages, images, documents, audio, video, location
  • Receive incoming messages
  • Mark messages as read/unread
  • Delete messages
  • Forward messages
  • Reply to specific messages

Groups

  • Create new groups
  • Add/remove participants
  • Change group settings (name, description, image)
  • Send messages to groups
  • Retrieve group metadata

Business Profile

  • Set up and update business profile (name, description, address, etc.)
  • Add product catalog
  • Configure business hours
  • Set up greeting messages

Message Templates

  • Create message templates for notifications
  • Submit templates for approval
  • Send template messages to users

Chatbots

  • Build conversational flows
  • Set up automated responses
  • Handoff to human agents when needed

Analytics

  • View message metrics (sent, delivered, read)
  • Track engagement rates
  • Monitor response times

Media

  • Upload and send images, audio, video, documents
  • Retrieve media files

Payments (in some regions)

  • Send payment requests
  • Process payments within chats

Broadcast Lists

  • Create broadcast lists
  • Send messages to multiple recipients

The WhatsApp Business API provides extensive capabilities to interact with these core data models programmatically, enabling businesses to build rich conversational experiences and automate customer communications at scale.