curl --request POST \
--url https://rest.newlead.ai/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://rest.newlead.ai/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://rest.newlead.ai/v1/messages"
payload = {}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"object": "message",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"lead_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"direction": "inbound",
"sender": "lead",
"origin": "lead",
"type": "text",
"text": "<string>",
"template": {
"name": "<string>",
"language": "<string>"
},
"attachments": [
{
"object": "attachment",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"type": "image",
"mime_type": "<string>",
"file_name": "<string>",
"file_size": 123,
"transcription": "<string>"
}
],
"reply_to_message_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "received",
"error": {
"code": 123,
"category": "recipient_not_reachable"
},
"created_at": "2023-11-07T05:31:56Z",
"sent_at": "2023-11-07T05:31:56Z",
"delivered_at": "2023-11-07T05:31:56Z",
"read_at": "2023-11-07T05:31:56Z",
"failed_at": "2023-11-07T05:31:56Z",
"lead_created": true,
"warnings": [
"pause_ai_failed"
]
}{
"error": {
"type": "invalid_request_error",
"code": "parameter_invalid",
"message": "phone must match pattern \"^\\+[1-9]\\d{6,14}$\".",
"param": "phone",
"request_id": "req_m3k2a9_4f1c2b7e",
"doc_url": "https://docs.newlead.ai/errors#parameter_invalid"
}
}{
"error": {
"type": "invalid_request_error",
"code": "parameter_invalid",
"message": "phone must match pattern \"^\\+[1-9]\\d{6,14}$\".",
"param": "phone",
"request_id": "req_m3k2a9_4f1c2b7e",
"doc_url": "https://docs.newlead.ai/errors#parameter_invalid"
}
}{
"error": {
"type": "invalid_request_error",
"code": "parameter_invalid",
"message": "phone must match pattern \"^\\+[1-9]\\d{6,14}$\".",
"param": "phone",
"request_id": "req_m3k2a9_4f1c2b7e",
"doc_url": "https://docs.newlead.ai/errors#parameter_invalid"
}
}Send a message
Free-form text to a lead, or an approved template to a lead or a phone number. If it cannot be sent, returns an error: 409 if we know before sending (24-hour window, do not contact, unapproved template), 400 recipient_invalid if WhatsApp rejects the recipient, and 502 if WhatsApp does not respond.
curl --request POST \
--url https://rest.newlead.ai/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{}'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({})
};
fetch('https://rest.newlead.ai/v1/messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://rest.newlead.ai/v1/messages"
payload = {}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"object": "message",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"lead_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"direction": "inbound",
"sender": "lead",
"origin": "lead",
"type": "text",
"text": "<string>",
"template": {
"name": "<string>",
"language": "<string>"
},
"attachments": [
{
"object": "attachment",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"type": "image",
"mime_type": "<string>",
"file_name": "<string>",
"file_size": 123,
"transcription": "<string>"
}
],
"reply_to_message_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": "received",
"error": {
"code": 123,
"category": "recipient_not_reachable"
},
"created_at": "2023-11-07T05:31:56Z",
"sent_at": "2023-11-07T05:31:56Z",
"delivered_at": "2023-11-07T05:31:56Z",
"read_at": "2023-11-07T05:31:56Z",
"failed_at": "2023-11-07T05:31:56Z",
"lead_created": true,
"warnings": [
"pause_ai_failed"
]
}{
"error": {
"type": "invalid_request_error",
"code": "parameter_invalid",
"message": "phone must match pattern \"^\\+[1-9]\\d{6,14}$\".",
"param": "phone",
"request_id": "req_m3k2a9_4f1c2b7e",
"doc_url": "https://docs.newlead.ai/errors#parameter_invalid"
}
}{
"error": {
"type": "invalid_request_error",
"code": "parameter_invalid",
"message": "phone must match pattern \"^\\+[1-9]\\d{6,14}$\".",
"param": "phone",
"request_id": "req_m3k2a9_4f1c2b7e",
"doc_url": "https://docs.newlead.ai/errors#parameter_invalid"
}
}{
"error": {
"type": "invalid_request_error",
"code": "parameter_invalid",
"message": "phone must match pattern \"^\\+[1-9]\\d{6,14}$\".",
"param": "phone",
"request_id": "req_m3k2a9_4f1c2b7e",
"doc_url": "https://docs.newlead.ai/errors#parameter_invalid"
}
}Authorizations
Headers
Up to 255 characters. Repeat the key with the same body within 24 hours and you get the same response plus an Idempotent-Replayed header set to true. 402, 409, 429 and 5xx responses (except send_outcome_unknown) are not stored: fix the cause and retry with the same key.
1 - 255Body
type text: free-form text to a lead_id; with the 24-hour window closed on WhatsApp it goes out as the agent's reopening template, and on Instagram it returns 409. type template: an approved template to a WhatsApp lead_id, or to a phone number (to) of an agent (text_agent_id), creating the lead if it does not exist.
Response
The message, with lead_created (false for text) and warnings (empty if there were none).
The message just sent, with lead_created (false for text) and warnings (empty if there were none).
received: a message from the lead. queued: stored but not yet sent to WhatsApp (in the queue, outside sending hours, waiting for template approval or with no channel connected). accepted: WhatsApp accepted it. sent, delivered, read and failed are confirmed by WhatsApp later.
received, queued, accepted, sent, delivered, read, failed