Execute a command on a number
With this endpoint you can execute a command on a number you connected to 2Chat.
Parameters
You will need to know the UUID
of the number you connected to 2Chat. You can get it using the List Numbers Endpoint.
The acceptable commands are the following and they must be part of the query path of the request. For example: https://api.p.2chat.io/open/whatsapp/channel/WPN.../connect
Field | Description |
---|---|
connect | Triggers a connect command to bring the number online with a QR Code. |
disconnect | Disconnects a connected number. This won't delete it from 2Chat. |
Invocation
For the following examples, we will use WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97
as the UUID
of the number we want to run commands on.
- cURL
- Python
- NodeJS
curl -X POST --location 'https://api.p.2chat.io/open/whatsapp/channel/WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97/connect' \
--header 'Content-Type: application/json' \
--header 'X-User-API-Key: your_api_key_here'
import requests
import json
url = "https://api.p.2chat.io/open/whatsapp/channel/WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97/connect"
headers = {
'Content-Type': 'application/json',
'X-User-API-Key': 'your_api_key_here'
}
response = requests.request("POST", url, headers=headers)
print(response.text)
const axios = require('axios');
let config = {
method: 'POST',
maxBodyLength: Infinity,
url: 'https://api.p.2chat.io/open/whatsapp/channel/WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97/connect',
headers: {
'Content-Type': 'application/json',
'X-User-API-Key': 'your_api_key_here'
}
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
Response
If the command executed correctly, you will see the following response.
{
"success": true
}
To check the status of the number after you executed a command, you can do it with the Channel Status Endpoint.