Skip to main content

The WhatsApp Cloud API allows businesses to integrate WhatsApp messaging into their apps or systems, enabling seamless customer communication at scale via Meta’s cloud-hosted service.

Project description

Getting Started with WhatsApp Cloud API

Introduction

WhatsApp Cloud API, hosted by Meta, is the official WhatsApp Business Platform API used for business messaging. This collection contains common queries, sample responses, and links to supporting documentation that can help you quickly get started with the API.

Cloud API Overview

Cloud API allows medium and large businesses to communicate with customers at scale. Using the API, businesses can build systems that connect thousands of customers with agents or bots, enabling both programmatic and manual communication. Additionally, businesses can integrate the API with numerous backend systems, such as CRM and marketing platforms.

https://developers.facebook.com/docs/whatsapp/cloud-api/overview

Getting Started with Cloud API

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

Get Started as a Solution Partner

This guide goes over the steps Solution Partners need to take in order to offer the Cloud API to their customers.

Migrating from On-Premises API to Cloud API

This guide explains how to migrate business phone numbers from On-Premises API to Cloud API.

Environment

This collection has a corresponding WhatsApp Cloud 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 use the collection to perform queries.

You can find most of these values in the WhatsApp Manager or the WhatsApp > Getting Started panel in the app dashboard. However, if you have an access token and your business portfolio ID, you can use queries in 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 Access Tokens 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 the business_id query string parameter value. 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 only relies on two permissions:

  • whatsapp_business_management

  • whatsapp_business_messaging

Note that if you get a user access token from the app dashboard, your app will automatically be granted these permissions (by you, on your behalf), so you can use the token to test right away.

Queries that target your business portfolio require the business_management permission, which you may also need based on your business use case. Most developers do not need this permission, however, as accessing your business portfolio is uncommon, and the Meta Business Suite provides nearly all of this functionality anyway.

Access token debugger

You can paste any token you generate 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.

Install the Package

The package is compatible with Python versions 3.7+. Install the package from PyPi using the following pip command:

pip install whatsapp-cloud-api-sdk==1.0.0

You can also view the package at: https://pypi.python.org/pypi/whatsapp-cloud-api-sdk/1.0.0

Test the SDK

You can test the generated SDK and the server with test cases. unittest is used as the testing framework and pytest is used as the test runner. You can run the tests as follows:

Navigate to the root directory of the SDK and run the following commands

pip install -r test-requirements.txt pytest

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
version str Default: 'DefaultParameterValue'
environment Environment The API environment.
Default: Environment.PRODUCTION
http_client_instance HttpClient The Http Client passed from the sdk user for making requests
override_http_client_configuration bool The value which determines to override properties of the passed Http Client from the sdk user
http_call_back HttpCallBack The callback value that is invoked before and after an HTTP call is made to an endpoint
timeout float The value to use for connection timeout.
Default: 60
max_retries int The number of times to retry an endpoint call if it fails.
Default: 0
backoff_factor float A backoff factor to apply between attempts after the second try.
Default: 2
retry_statuses Array of int The http statuses on which retry is to be done.
Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]
retry_methods Array of string The http methods on which retry is to be done.
Default: ['GET', 'PUT']
bearer_auth_credentials BearerAuthCredentials The credential object for OAuth 2 Bearer token

The API client can be initialized as follows:

from whatsappcloudapi.configuration import Environment
from whatsappcloudapi.http.auth.o_auth_2 import BearerAuthCredentials
from whatsappcloudapi.whatsappcloudapi_client import WhatsappcloudapiClient

client = WhatsappcloudapiClient(
    bearer_auth_credentials=BearerAuthCredentials(
        access_token='AccessToken'
    ),
    environment=Environment.PRODUCTION,
    version='DefaultParameterValue'
)

Authorization

This API uses the following authentication schemes.

List of APIs

SDK Infrastructure

HTTP

Utilities

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whatsapp_cloud_api_sdk-1.0.0.tar.gz (106.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whatsapp_cloud_api_sdk-1.0.0-py3-none-any.whl (484.8 kB view details)

Uploaded Python 3

File details

Details for the file whatsapp_cloud_api_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: whatsapp_cloud_api_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 106.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for whatsapp_cloud_api_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 21b800b8175492462c6cb06002f533de0cdff77413ac27bbb3f598cf3db53868
MD5 0f068da1bc055da6813dc2462f7c2195
BLAKE2b-256 f51d866e081a4069d75a341de5d83da881b86c1b9db49dc3b89837bf972a0a93

See more details on using hashes here.

File details

Details for the file whatsapp_cloud_api_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for whatsapp_cloud_api_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b1e0b5570cfff5188815ad25a35bc877c1cd19342b6bc21a09d653d2664f77e
MD5 2d8543b5194f1d58a4fd31a42e450205
BLAKE2b-256 6f3e3c3e08c3bb6c43fbee65c11336bf1b8354e444675c820646d71925564571

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page