cloud-api-whatsapp
v1.0.0
Published
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.
Downloads
13
Readme
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
Run the following command from your project directory to install the package from npm:
npm install [email protected]For additional package details, see the Npm page for the [email protected] npm.
Test the SDK
To validate the functionality of this SDK, you can execute all tests located in the test directory. This SDK utilizes Jest as both the testing framework and test runner.
To run the tests, navigate to the root directory of the SDK and execute the following command:
npm run testOr you can also run tests with coverage report:
npm run test:coverageInitialize 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 | string | Default: 'DefaultParameterValue' |
| environment | Environment | The API environment. Default: Environment.Production |
| timeout | number | Timeout for API calls.Default: 0 |
| httpClientOptions | Partial<HttpClientOptions> | Stable configurable http client options. |
| unstableHttpClientOptions | any | Unstable configurable http client options. |
| bearerAuthCredentials | BearerAuthCredentials | The credential object for bearerAuth |
The API client can be initialized as follows:
import { Client, Environment } from 'cloud-api-whatsapp';
const client = new Client({
bearerAuthCredentials: {
accessToken: 'AccessToken'
},
timeout: 0,
environment: Environment.Production,
version: 'DefaultParameterValue',
});Authorization
This API uses the following authentication schemes.
List of APIs
- Get Started
- Whats App Business Accounts WAB As
- Phone Numbers
- Webhook Payload Reference
- Webhook Subscriptions
- Create Flow
- Update Flow
- Setup Endpoint Encryption
- Send Flow
- Get Endpoint Metrics
- Typingindicators
- Business Profiles
- Commerce Settings
- Payments API-SG
- Payments API-IN
- Q Rcodes
- Business Portfolio
- On Prem Account Migration
- Block Users
- Business Compliance
- Registration
- Messages
- Templates
- Media
- Analytics
- Billing
- Examples
