sentdm/whats-app-business-management-api

The WhatsApp Business Management API allows you to programmatically manage your WhatsApp Business Account assets, such as message templates and phone numbers.

1.0.1 2025-01-04 23:49 UTC

This package is not auto-updated.

Last update: 2025-05-26 00:02:22 UTC


README

Introduction

This public collection contains common queries, sample responses, and links to supporting documentation for the Business Management API.

Requirements

To use this collection you must have a Meta business portfolio, a WhatsApp Business Account (WABA), and a business phone number. If you complete the steps in the Cloud API Get Started guide, all of these will be created for you.

Environment

This collection has a corresponding Business Management API Postman environment which you must select when using the collection. Set current values for the variables defined in this environment if you wish to perform the queries in the collection.

You can find most of these values in the WhatsApp Manager or the WhatsApp > Getting Started panel in the app dashboard, but if you have an access token and your business portfolio ID, you can use the collection to get the remaining values.

Access tokens

The API supports both user and system user access tokens. You can get a user access token by loading your app in the app dashboard and navigating to the WhatsApp > Getting Started panel. Alternatively you can use the Graph API Explorer to generate one.

Since user access tokens expire after 24 hours, you'll likely want to generate a system user access token, which lasts up to 60 days (or permanently, if you wish). See System Users to learn how to create a system user and system user access token.

Once you have your token, save it as a current value in the environment.

Business portfolio ID

You can get your business portfolio ID by signing into the Meta Business Suite. The ID appears in the URL as business_id. Once you save this as a current value in the environment, go to the WhatsApp Business Account (WABA) folder and run the Get all owned WABAs query. This will return your WABA ID, which you can save to your environment and then use to determine your business phone number ID.

Permissions

The API technically only relies on two permissions, but since you're likely going to be using the API to generate assets in order to send messages using our other APIs, we recommend that you grant your these three permissions:

  • business_management
  • whatsapp_business_management
  • whatsapp_business_messaging

Note that if you get a user access token from the app dashboard, it automatically grants your app all three of these permissions.

Access token debugger

You can paste your token into the access token debugger to see what type of token it is and what permission you have granted to your app.

Pagination

Endpoints that return lists/collections may paginate results (you'll see previous and next properties in the response). Use the URLs from these properties to get the previous or next set of results. Note that if you click one of these links in Postman, it will open a new query in a new tab which you must save before running (otherwise it can't read your environment variables), so you may wish to cut and paste the URL and run the query in the same tab in which it was returned.

Contact Maintainers Sent.dm

Install the Package

Run the following command to install the package and automatically add the dependency to your composer.json file:

composer require "sentdm/whats-app-business-management-api:1.0.1"

Or add it to the composer.json file manually as given below:

"require": {
    "sentdm/whats-app-business-management-api": "1.0.1"
}

You can also view the package at: https://packagist.org/packages/sentdm/whats-app-business-management-api#1.0.1

Test the SDK

Unit tests in this SDK can be run using PHPUnit.

  1. First install the dependencies using composer including the require-dev dependencies.
  2. Run vendor\bin\phpunit --verbose from commandline to execute tests. If you have installed PHPUnit globally, run tests using phpunit --verbose instead.

You can change the PHPUnit test configuration in the phpunit.xml file.

Initialize the API Client

Note: Documentation for the client can be found here.

The following parameters are configurable for the API Client:

Parameter Type Description
apiVersion string Default: 'DefaultParameterValue'
environment Environment The API environment.
Default: Environment.PRODUCTION
timeout int Timeout for API calls in seconds.
Default: 0
enableRetries bool Whether to enable retries and backoff feature.
Default: false
numberOfRetries int The number of retries to make.
Default: 0
retryInterval float The retry time interval between the endpoint calls.
Default: 1
backOffFactor float Exponential backoff factor to increase interval between retries.
Default: 2
maximumRetryWaitTime int The maximum wait time in seconds for overall retrying requests.
Default: 0
retryOnTimeout bool Whether to retry on request timeout.
Default: true
httpStatusCodesToRetry array Http status codes to retry against.
Default: 408, 413, 429, 500, 502, 503, 504, 521, 522, 524
httpMethodsToRetry array Http methods to retry against.
Default: 'GET', 'PUT'
bearerCredentials BearerCredentials The Credentials Setter for OAuth 2 Bearer token
oauth2Credentials Oauth2Credentials The Credentials Setter for OAuth 2 Implicit Grant

The API client can be initialized as follows:

$client = WhatsAppBusinessManagementAPIClientBuilder::init()
    ->bearerCredentials(
        BearerCredentialsBuilder::init(
            'AccessToken'
        )
    )
    ->oauth2Credentials(
        Oauth2CredentialsBuilder::init(
            'OAuthClientId',
            'OAuthRedirectUri'
        )
    )
    ->environment(Environment::PRODUCTION)
    ->apiVersion('DefaultParameterValue')
    ->build();

Authorization

This API uses the following authentication schemes.

List of APIs

Classes Documentation