whatsapp-cloud-api-sdk 1.0.0
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.
Requires Python: >=3.7


# Getting Started with WhatsApp Cloud API

## Introduction

[WhatsApp Cloud API](https://developers.facebook.com/docs/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](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](https://developers.facebook.com/docs/whatsapp/cloud-api/get-started) guide, these assets will be created for you.

### Get Started as a Solution Partner

[This guide](https://developers.facebook.com/docs/whatsapp/solution-providers/get-started-for-solution-partners) 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](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/migrating-from-onprem-to-cloud) business phone numbers from On-Premises API to Cloud API.

### Environment

This collection has a corresponding WhatsApp Cloud API Postman [environment](https://learning.postman.com/docs/sending-requests/managing-environments/) 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](https://business.facebook.com/wa/manage/home/) or the **WhatsApp** > **Getting Started** panel in the [app dashboard](https://developers.facebook.com/apps). 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](https://developers.facebook.com/apps) and navigating to the WhatsApp > Getting Started panel. Alternatively you can use the [Graph API Explorer](https://developers.facebook.com/tools/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](https://developers.facebook.com/docs/whatsapp/business-management-api/get-started#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](https://business.facebook.com). 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](https://developers.facebook.com/tools/debug/accesstoken/) 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](https://developers.facebook.com/docs/graph-api/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:

```bash
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.](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/client.md)

The following parameters are configurable for the API Client:

| Parameter | Type | Description |
|  --- | --- | --- |
| version | `str` | *Default*: `'DefaultParameterValue'` |
| environment | `Environment` | The API environment. <br> **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. <br> **Default: 60** |
| max_retries | `int` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
| backoff_factor | `float` | A backoff factor to apply between attempts after the second try. <br> **Default: 2** |
| retry_statuses | `Array of int` | The http statuses on which retry is to be done. <br> **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. <br> **Default: ['GET', 'PUT']** |
| bearer_auth_credentials | [`BearerAuthCredentials`](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/auth/oauth-2-bearer-token.md) | The credential object for OAuth 2 Bearer token |

The API client can be initialized as follows:

```python
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.

* [`bearer (OAuth 2 Bearer token)`](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/auth/oauth-2-bearer-token.md)

## List of APIs

* [Get Started](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/get-started.md)
* [Whats App Business Accounts WAB As](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/whats-app-business-accounts-wab-as.md)
* [Phone Numbers](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/phone-numbers.md)
* [Webhook Payload Reference](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/webhook-payload-reference.md)
* [Webhook Subscriptions](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/webhook-subscriptions.md)
* [Create Flow](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/create-flow.md)
* [Update Flow](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/update-flow.md)
* [Setup Endpoint Encryption](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/setup-endpoint-encryption.md)
* [Send Flow](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/send-flow.md)
* [Get Endpoint Metrics](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/get-endpoint-metrics.md)
* [Typingindicators](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/typingindicators.md)
* [Business Profiles](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/business-profiles.md)
* [Commerce Settings](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/commerce-settings.md)
* [Payments API-SG](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/payments-api-sg.md)
* [Payments API-IN](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/payments-api-in.md)
* [Q Rcodes](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/q-rcodes.md)
* [Business Portfolio](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/business-portfolio.md)
* [On Prem Account Migration](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/on-prem-account-migration.md)
* [Block Users](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/block-users.md)
* [Business Compliance](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/business-compliance.md)
* [Registration](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/registration.md)
* [Messages](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/messages.md)
* [Templates](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/templates.md)
* [Media](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/media.md)
* [Analytics](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/analytics.md)
* [Billing](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/billing.md)
* [Examples](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/controllers/examples.md)

## SDK Infrastructure

### HTTP

* [HttpResponse](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/http-response.md)
* [HttpRequest](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/http-request.md)

### Utilities

* [ApiHelper](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/api-helper.md)
* [HttpDateTime](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/http-date-time.md)
* [RFC3339DateTime](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/rfc3339-date-time.md)
* [UnixDateTime](https://www.github.com/MuHamza30/whatsapp-api-python-sdk/tree/1.0.0/doc/unix-date-time.md)