import { PeriskopeApi } from '@periskope/periskope-client';
const client = new PeriskopeApi({
authToken: 'YOUR_API_KEY',
phone: '919876543210', // the phone to act with (x-phone)
});
async function main() {
const response = await client.messages.sendMessage({
chat_id: '911111111111@c.us',
});
console.log(response);
}
main();curl -X POST 'https://api.periskope.app/v1/message/send' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'x-phone: 919876543210' \
-H 'Content-Type: application/json' \
-d '{
"chat_id": "911111111111@c.us"
}'{
"status": "queued",
"unique_id": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"queue_id": "00000000-0000-0000-0000-000000000000",
"queue_position": 0,
"track_by": {
"unique_id": "GET /messages/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/status"
}
}{
"code": "ERROR",
"message": "The phone is off or its server is unreachable",
"status": 400
}{
"code": "UNAUTHORIZED_ERROR",
"message": "Invalid bearer auth token",
"status": 401
}{
"code": "NOT_FOUND_ERROR",
"message": "x-phone omitted and the group chat was not found on any phone of the org",
"status": 404
}{
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"status": 422,
"fields": {
"body.chat_id": {
"message": "chat_id is required"
}
}
}{
"code": "RATE_LIMIT_ERROR",
"message": "You can only make 100 requests per second",
"status": 429
}{
"code": "UNKNOWN_ERROR",
"message": "Internal server error",
"status": 500
}Send Message
Sends a message (text, media and/or poll) to a chat from the phone in the x-phone header. For group chats the header can be omitted — a connected phone that is in the group is selected automatically, within the token’s phone scopes. Sending is asynchronous — track the returned unique_id via GET /message//status.
import { PeriskopeApi } from '@periskope/periskope-client';
const client = new PeriskopeApi({
authToken: 'YOUR_API_KEY',
phone: '919876543210', // the phone to act with (x-phone)
});
async function main() {
const response = await client.messages.sendMessage({
chat_id: '911111111111@c.us',
});
console.log(response);
}
main();curl -X POST 'https://api.periskope.app/v1/message/send' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'x-phone: 919876543210' \
-H 'Content-Type: application/json' \
-d '{
"chat_id": "911111111111@c.us"
}'{
"status": "queued",
"unique_id": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"queue_id": "00000000-0000-0000-0000-000000000000",
"queue_position": 0,
"track_by": {
"unique_id": "GET /messages/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/status"
}
}{
"code": "ERROR",
"message": "The phone is off or its server is unreachable",
"status": 400
}{
"code": "UNAUTHORIZED_ERROR",
"message": "Invalid bearer auth token",
"status": 401
}{
"code": "NOT_FOUND_ERROR",
"message": "x-phone omitted and the group chat was not found on any phone of the org",
"status": 404
}{
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"status": 422,
"fields": {
"body.chat_id": {
"message": "chat_id is required"
}
}
}{
"code": "RATE_LIMIT_ERROR",
"message": "You can only make 100 requests per second",
"status": 429
}{
"code": "UNKNOWN_ERROR",
"message": "Internal server error",
"status": 500
}Authorizations
Your Periskope API token, sent as Authorization: Bearer <token>. Generate one from the Periskope dashboard under Settings → API & Webhooks. API access requires an active Pro or Enterprise plan.
Headers
Phone to send from: country code + number without symbols or spaces (e.g. 911111111111), or a phone_id (phone-xxxxxxxxxxxx). Required for 1-1 chats. For group chats it can be omitted — a connected phone that is in the group is selected automatically, within the token's phone scopes.
"919876543210"
Body
Chat to send the message to. For group chats, the chat_id ending with @g.us; for 1-1 chats, country code + number of the contact, optionally suffixed with @c.us (e.g. 911111111111 or 911111111111@c.us).
1"911111111111@c.us"
The text body of the message, or the caption when media is provided. Supports the basic WhatsApp markdown formatting (bold, italic, strikethrough, monospace).
"Hello World"
Media to send — a document, image, video, audio file or voice note. Provide either a public url or base64 filedata. The message text, when given, becomes the caption.
Show child attributes
Show child attributes
Poll to send instead of a plain message. The resulting message has message_type poll_creation.
Show child attributes
Show child attributes
message_id of an existing message in the chat to reply to. The sent message quotes it.
"true_911111111111@c.us_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Additional sending options
Show child attributes
Show child attributes
Response
The queued message
Always queued — messages are not sent synchronously, they are queued on the phone and submitted in the background
queued Provisional id of the message. Use it with GET /message/{unique_id}/status to track delivery, or with GET /message/{message_id} once processed. The resulting message record carries it as unique_id.
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Id of the queue job on the phone. The resulting message record carries it as sent_message_id, and the queue endpoints accept it as queue_id.
"00000000-0000-0000-0000-000000000000"
Position of the job in the send queue at the moment it was enqueued (0 = next in line)
0
Convenience pointers for tracking the message
Show child attributes
Show child attributes
Was this page helpful?