Ever wanted to create an API out of your WhatsApp account?
Tags: node, javascript, whatsapp, express
Published: 2022-03-05 16:13:06


## What is Whatsapp? 🤷
![dogs-communicating](https://media.giphy.com/media/jmdSl4757OteE/giphy.gif)
WhatsApp is a mobile messaging application which allows you to send and receive messages without having to pay for SMS.

WhatsApp is the most popular messaging app in the world with over 1 billion monthly active users.

WhatsApp's end-to-end encryption ensures that your messages are secure from third parties like hackers and government surveillance programs.

## What can you do with WhatsApp API? 😕
Usage Scenarios for the API

1. Sending programmatic responses to contacts.
2. Providing Customer support to a Business.
3. Marketing.
4. etc.

## Let's Begin 🌟
Note: Install [Node.js](https://nodejs.org/en/download/) v16+ if you haven’t already.

We are going to use [whatsapp-api-nodejs](https://github.com/salman0ansari/whatsapp-api-nodejs) that converts users WhatsApp account into an API.

In addition, [whatsapp-api-nodejs](https://github.com/salman0ansari/whatsapp-api-nodejs) can 🤯: 

- send media message such as image, video, document etc
- send response message data to a specified webhook URL
- send messages to groups
- downloads contacts profiles pic
- send template message
- create, delete and join a group
- etc.

To get started clone the repository from Github:
```
git clone https://github.com/salman0ansari/whatsapp-api-nodejs.git
```
Change directory into the project and run 
```
npm install
``` 
It will take some time to install the dependencies.

**If you going to use webhook make sure to create a `.env` file in the project root. Inside the file add:**
```
WEBHOOK_URL=https://your webhook url
```

Finally, run `npm run start` in the project root to start the server. Our applications will be accessed at 
```
http://localhost:3333
```
### Init Instance 🌌
To initialise a server make a GET request 
**Note: Don't forgot to save KEY value.**
```
ENDPOINT: /init
```
![init](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/76hkc60z1pbqc1q84mcm.png)

### Scanning QR Code 📱
To scan QR code make a GET request
```
ENDPOINT: /qrcode?key=KEY
QUERY -> KEY = Instance Key
```

**Note: make sure to scan QR ASAP after you init a Instance.**

![qrcode](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oujggjfyxuncuu12933f.png)

### Sending a Message 📨
To send a Text message make a POST request 
```
ENDPOINT: /sendText?key=KEY
QUERY -> KEY = Instance Key
REQUEST BODY:
{
  "msg_data": {
    "id": "919999999999",
    "message": "Hello World"
  }
}
```
![sendText](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20vd03x35254yul921xt.png)

### API-Docs 📑
To check more enpoint make a GET request 
```
ENDPOINT: /api-docs
```

![api-docs](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zmpdvu9h5ej08pfweknj.png)

### THAT'S IT 🏁
In the next tutorial we will learn how can we use this API to send memes daily to your friend.

### Links 🔗
whatsapp-api-nodejs: [https://github.com/salman0ansariwhatsapp-api-nodejs](https://github.com/salman0ansari/whatsapp-api-nodejs)

nodejs: [https://nodejs.org](https://nodejs.org/en/download/)