Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

WhatsappApiSDK

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

WhatsappApiSDK

WhatsApp Cloud API C# SDK

nugetNuGet
Version
1.0.0
Version published
Maintainers
1
Created
Source

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.

Requirements

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.

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

If you are building with .NET CLI tools then you can also use the following command:

dotnet add package WhatsappApiSDK --version 1.0.0

You can also view the package at: https://www.nuget.org/packages/WhatsappApiSDK/1.0.0

Test the SDK

The generated SDK also contain one or more Tests, which are contained in the Tests project. In order to invoke these test cases, you will need NUnit 3.0 Test Adapter Extension for Visual Studio. Once the SDK is complied, the test cases should appear in the Test Explorer window. Here, you can click Run All to execute these test cases.

Initialize the API Client

Note: Documentation for the client can be found here.

The following parameters are configurable for the API Client:

ParameterTypeDescription
VersionstringDefault: "DefaultParameterValue"
EnvironmentEnvironmentThe API environment.
Default: Environment.Production
TimeoutTimeSpanHttp client timeout.
Default: TimeSpan.FromSeconds(100)
BearerAuthCredentialsBearerAuthCredentialsThe Credentials Setter for OAuth 2 Bearer token

The API client can be initialized as follows:

WhatsAppCloudAPIClient client = new WhatsAppCloudAPIClient.Builder()
    .BearerAuthCredentials(
        new BearerAuthModel.Builder(
            "AccessToken"
        )
        .Build())
    .Environment(WhatsAppCloudAPI.Standard.Environment.Production)
    .Version("DefaultParameterValue")
    .Build();

Authorization

This API uses the following authentication schemes.

List of APIs

Classes Documentation

Keywords

WhatsApp

FAQs

Package last updated on 04 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts