Create or update a lead
curl --request POST \
--url https://rest.newlead.ai/v1/leads \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"text_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"phone": "+34600111222"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({text_agent_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a', phone: '+34600111222'})
};
fetch('https://rest.newlead.ai/v1/leads', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://rest.newlead.ai/v1/leads"
payload = {
"text_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"phone": "+34600111222"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"object": "lead",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"text_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"voice_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"phone": "<string>",
"email": "<string>",
"username": "<string>",
"channel": "whatsapp",
"status": "active",
"source": {
"type": "whatsapp",
"lead_ad": {
"form_id": "<string>",
"ad_id": "<string>",
"leadgen_id": "<string>"
}
},
"summary": "<string>",
"variables": {},
"qualification": {
"status": "not_started",
"completed_at": "2023-11-07T05:31:56Z",
"answers": [
{
"question_id": "<string>",
"question": "<string>",
"value": "<string>",
"value_label": "<string>"
}
]
},
"do_not_contact": true,
"has_replied": true,
"ai_paused": true,
"ai_paused_until": "2023-11-07T05:31:56Z",
"messaging_window_expires_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"last_activity_at": "2023-11-07T05:31:56Z"
}{
"object": "lead",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"text_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"voice_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"phone": "<string>",
"email": "<string>",
"username": "<string>",
"channel": "whatsapp",
"status": "active",
"source": {
"type": "whatsapp",
"lead_ad": {
"form_id": "<string>",
"ad_id": "<string>",
"leadgen_id": "<string>"
}
},
"summary": "<string>",
"variables": {},
"qualification": {
"status": "not_started",
"completed_at": "2023-11-07T05:31:56Z",
"answers": [
{
"question_id": "<string>",
"question": "<string>",
"value": "<string>",
"value_label": "<string>"
}
]
},
"do_not_contact": true,
"has_replied": true,
"ai_paused": true,
"ai_paused_until": "2023-11-07T05:31:56Z",
"messaging_window_expires_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"last_activity_at": "2023-11-07T05:31:56Z"
}{
"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"
}
}Leads
Create or update a lead
If the agent already has a WhatsApp or Lead Ads lead with that phone number, in any of its forms, updates it and returns 200; otherwise creates it and returns 201. A voice or web chat lead with the same number does not count. The name changes only if you send it, and variables are merged with the existing ones.
POST
/
leads
Create or update a lead
curl --request POST \
--url https://rest.newlead.ai/v1/leads \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"text_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"phone": "+34600111222"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({text_agent_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a', phone: '+34600111222'})
};
fetch('https://rest.newlead.ai/v1/leads', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://rest.newlead.ai/v1/leads"
payload = {
"text_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"phone": "+34600111222"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"object": "lead",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"text_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"voice_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"phone": "<string>",
"email": "<string>",
"username": "<string>",
"channel": "whatsapp",
"status": "active",
"source": {
"type": "whatsapp",
"lead_ad": {
"form_id": "<string>",
"ad_id": "<string>",
"leadgen_id": "<string>"
}
},
"summary": "<string>",
"variables": {},
"qualification": {
"status": "not_started",
"completed_at": "2023-11-07T05:31:56Z",
"answers": [
{
"question_id": "<string>",
"question": "<string>",
"value": "<string>",
"value_label": "<string>"
}
]
},
"do_not_contact": true,
"has_replied": true,
"ai_paused": true,
"ai_paused_until": "2023-11-07T05:31:56Z",
"messaging_window_expires_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"last_activity_at": "2023-11-07T05:31:56Z"
}{
"object": "lead",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"text_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"voice_agent_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"contact_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"name": "<string>",
"phone": "<string>",
"email": "<string>",
"username": "<string>",
"channel": "whatsapp",
"status": "active",
"source": {
"type": "whatsapp",
"lead_ad": {
"form_id": "<string>",
"ad_id": "<string>",
"leadgen_id": "<string>"
}
},
"summary": "<string>",
"variables": {},
"qualification": {
"status": "not_started",
"completed_at": "2023-11-07T05:31:56Z",
"answers": [
{
"question_id": "<string>",
"question": "<string>",
"value": "<string>",
"value_label": "<string>"
}
]
},
"do_not_contact": true,
"has_replied": true,
"ai_paused": true,
"ai_paused_until": "2023-11-07T05:31:56Z",
"messaging_window_expires_at": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"last_activity_at": "2023-11-07T05:31:56Z"
}{
"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
BearerAuthApiKeyHeader
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.
Required string length:
1 - 255Body
application/json
Response
Already existed: the updated lead.