DEV Community

Cover image for How to send a post to WhatsApp Channel via API
WhatsApp API for developers
WhatsApp API for developers

Posted on • Edited on

How to send a post to WhatsApp Channel via API

Our Cloud API supports WhatsApp Channels, a brand-new feature introduced by WhatsApp. It’s a unidirectional broadcast tool where administrators can send text, photos, videos, stickers, and polls. And users receive push notifications of updates from the channel like a private message.

Automate and integrate WhatsApp channels with our API

To work with our service, you need to have an account and connect any number to an available channel on the dashboard. In order to automate WhatsApp, you need to sync our API with your phone number. Here's how: navigate to your personal dashboard, select your channel, and get a QR code there.

To send a message to the channel you need to know the channel ID.

In order to find out the identifier use the following method: GET /newsletters



import requests

url = "https://gate.whapi.cloud/newsletters?count=100"

headers = {
    "accept": "application/json",
    "authorization": "Bearer iBNBwpo21BDCsbdvVwShV4czcXPbBmcs"
}

response = requests.get(url, headers=headers)

print(response.text)


Enter fullscreen mode Exit fullscreen mode

The channel ID looks like this: 120363171744447809@newsletter

Once you know the channel ID, you can use the method to send any message. For example, a text message:



import requests

url = "https://gate.whapi.cloud/messages/text"

payload = {
    "typing_time": 0,
    "to": "120363171744447809@newsletter",
    "body": "Hello, world!"
}
headers = {
    "accept": "application/json",
    "content-type": "application/json",
    "authorization": "Bearer iBNBwpo21BDCsbdvVwShV4czcXPbBmcs"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)


Enter fullscreen mode Exit fullscreen mode

In the “to” parameter you insert the ID of the channel ( 120363171744447809@newsletter ) you want to send the message to. And in the “body”, the text of the message.


Remember, if you have any questions or issues along the way, our support team is always available to help. We value every user and strive to ensure that your experience with our API is as smooth and efficient as possible.

You can write to the web chat widget on our main website, or in your personal account. Or write to us by e-mail: care@whapi.cloud

Top comments (1)

Collapse
 
bbbb_bbbb_13caa4468930a05 profile image
Bbbb Bbbb

Does it free or should pay ?