[go: up one dir, main page]

Skip to content

SendContact#

Test Postman

The method is aimed for sending a contact message. Contact visit card is created and sent to a chat. The message will be added to the send queue. Linked device not required when sending. Messages will be kept for 24 hours in the queue until instance will be authorized The rate at which messages are sent from the queue is managed by Message sending delay parameter.

Request#

To send a contact message, you have to execute a request at:

POST
{{apiUrl}}/waInstance{{idInstance}}/sendContact/{{apiTokenInstance}}

For apiUrl, idInstance and apiTokenInstance request parameters, refer to Before you start section.

Request parameters#

Parameter Type Mandatory Description
chatId string Yes Chat Id
contact object Yes Contact object
quotedMessageId string No Quoted message Id. If present, the message will be sent quoting the specified chat message.
Quoting a message is only possible from the same chat to which it is sent.
To send messages from another chat, use the ForwardMessages method

contact object parameters:

Parameter Type Mandatory Description
phoneContact integer Yes contact phone number in international format (no +) 11 or 12 digits
firstName string If middleName, lastName, company not specified Contact name
middleName string If firstName, lastName, company not specified Contact middle name
lastName string If middleName, firstName, company not specified Contact last name
company string If middleName, lastName, firstName not specified Contact company name

Request Example body#

Sending a message to a personal chat:

{
    "chatId": "11001234567@c.us",
    "contact": {
        "phoneContact": 79001234568,
        "firstName": "Artem",
        "middleName": "Petrovich",
        "lastName": "Evpatoriysky",
        "company": "Bicycle"
    }
}

Sending a message to a group chat:

{
    "chatId": "11001234567-1581234048@g.us",
    "contact": {
        "phoneContact": 79001234568,
        "firstName": "Artem",
        "middleName": "Petrovich",
        "lastName": "Evpatoriysky",
        "company": "Bicycle"
    }
}

Sending a quoted message:

{
    "chatId": "11001234567@c.us",
    "quotedMessageId": "361B0E63F2FDF95903B6A9C9A102F34B",
    "contact": {
        "phoneContact": 79001234568,
        "firstName": "Artem",
        "middleName": "Petrovich",
        "lastName": "Evpatoriysky",
        "company": "Bicycle"
    }
}

Response#

Response parameters#

Parameter Type Description
idMessage string Outgoing message Id

Response body example#

{
    "idMessage": "3EB0C767D097B7C7C030"
}

SendContact errors#

For a list of errors common to all methods, refer to Common errors section

HTTP code Error identifier Description
400 Bad Request
Validation failed
Validation error
400 Validation failed.
Details: 'value' must have at least 1 key
Validation failed. Details: value must have at least 1 key
400 Validation failed.
Details: 'contact.phoneContact' must be a number
Invalid data type for field contact.phoneContact
400 Validation failed.
Details: 'contact.phoneContact' must be a safe number
The value of the field contact.phoneContact exceeds maximum safe integer value
500 Internal Server Error
request entity too large
Exceeding the allowed Json length (>100kb)

Sending with invalid Quoted message ID

If the quotedMessageId in the request body is incorrect, the system will return code 200 and the message ID, but the message will not be sent

Request examples#

import requests

url = "{{apiUrl}}/waInstance{{idInstance}}/sendContact/{{apiTokenInstance}}"

payload = {
    "chatId": "11001234567@c.us",  
    "contact": {
     "phoneContact": "79001234568",
     "firstName": "Artem", 
     "middleName": "Petrovich", 
     "lastName": "Evpatoriysky", 
     "company": "Bicycle"
    }
}

headers = {
    'Content-Type': 'application/json'
}

response = requests.post(url, json=payload, headers=headers)

print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/sendContact/{{apiTokenInstance}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "chatId": "123456780910@c.us",
    "contact": {
        "phoneContact": 111111111111,
        "firstName": "Артем",
        "middleName": "Петрович",
        "lastName": "Евпаторийский",
        "company": "Велосипед"
    }
}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/sendContact/")
    .append({{apiTokenInstance}});

var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

var jsonBody = "{\r\n\t\"chatId\": \"11001234567@c.us\",\r\n\t\"contact\": {\r\n\t\t\"phoneContact\": 79001234568,\r\n    \t\"firstName\": \"Артем\",\r\n\t\t\"middleName\": \"Петрович\",\r\n\t\t\"lastName\": \"Евпаторийский\",\r\n\t\t\"company\": \"Велосипед\"\r\n\t}\r\n}\r\n";

var requestEntity = new HttpEntity<>(jsonBody, headers);

var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.POST, requestEntity, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
    .append({{apiUrl}})
    .append("/waInstance").append({{idInstance}})
    .append("/sendContact/")
    .append({{apiTokenInstance}});

var response = Unirest.post(requestUrl.toString())
    .header("Content-Type", "application/json")
    .body("{\r\n\t\"chatId\": \"11001234567@c.us\",\r\n\t\"contact\": {\r\n\t\t\"phoneContact\": 79001234568,\r\n    \t\"firstName\": \"Артем\",\r\n\t\t\"middleName\": \"Петрович\",\r\n\t\t\"lastName\": \"Евпаторийский\",\r\n\t\t\"company\": \"Велосипед\"\r\n\t}\r\n}\r\n")
    .asString();

System.out.println(response);
Sub SendContact()
    Dim url As String
    Dim RequestBody As String
    Dim http As Object
    Dim response As String

    ' The apiUrl, idInstance and apiTokenInstance values are available in console, double brackets must be removed
    url = "{{apiUrl}}/waInstance{{idInstance}}/sendContact/{{apiTokenInstance}}"

    ' chatId - chat identifier, phoneContact - contact phone number in international format (without +) 11 or 12 digits, firstName - contact name, middleName - contact's middle name, lastName - contact's last name, company - contact's company name
    RequestBody = "{""chatId"":""71234567890@c.us"",""contact"":{""phoneContact"":70123456789,""firstName"":""Artyom"",""middleName"":""Petrovich"",""lastName"":""Evpatorsky"",""company"":""Bicycle""}}"

    Set http = CreateObject("MSXML2.XMLHTTP")

    With http
        .Open "POST", url, False
        .setRequestHeader "Content-Type", "application/json"
        .send RequestBody
    End With

    response = http.responseText

    Debug.Print response

    ' Outputting the answer to the desired cell
    Range("A1").Value = response

    Set http = Nothing
End Sub