GetContacts#
The method is intended for getting the contact list of the current account.
Updating contact information may take up to 5 minutes.
The method uses limits on the request rate per second.
Request#
To get the contact list, you need to execute a request at:
GET
{{apiUrl}}/waInstance{{idInstance}}/getContacts/{{apiTokenInstance}}
To get the apiUrl, idInstance and apiTokenInstance request parameters, refer to the Before you start section.
Request URL parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
count | integer | No | When the number count={{number}} is specified, the specified number of contacts is displayedIf there are fewer contacts than the specified number, all contacts are displayed By default all contacts are shown |
Example of a request with a specified number of contacts#
GET
{{apiUrl}}/waInstance{{idInstance}}/getContacts/{{apiTokenInstance}}?count=50
Response#
Response fields#
| Field | Type | Description |
|---|---|---|
chatId | string | Chat or group chat identifier |
name | string | Name of the user or group in Telegram |
contactName | string | Contact name from the contact book |
type | string | Contact type. For contacts it is always user |
phoneNumber | integer | Phone number (if it is hidden by privacy settings or the contact is a group, it takes the value 0) |
username | string | Telegram username that starts with the @ character |
Response body example#
[
{
"chatId": "10000000",
"name": "Vasilisa",
"contactName": "Vasilisa the Wise",
"type": "user",
"phoneNumber": 79876543210,
"username": "@vasilisa"
},
{
"chatId": "10000001",
"name": "Ivan",
"contactName": "Ivan Tsarevich",
"type": "user",
"phoneNumber": 79998887766,
"username": ""
},
{
"chatId": "10000002",
"name": "Frog",
"contactName": "Frog Princess",
"type": "user",
"phoneNumber": 0,
"username": "@tsarevna_frog"
}
]
Errors#
For the list of errors common to all methods, see the Common errors section
| HTTP code | Error description | Possible solutions |
|---|---|---|
| 200 | The method returns an empty array [] | Contact the technical support service. |
Code examples#
import requests
url = "{{apiUrl}}/waInstance{{idInstance}}/getContacts/{{apiTokenInstance}}"
payload = {}
headers= {}
response = requests.request("GET", url, headers=headers, data = payload)
print(response.text.encode('utf8'))
curl --location '{{apiUrl}}/waInstance{{idInstance}}/getContacts/{{apiTokenInstance}}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/getContacts/")
.append({{apiTokenInstance}});
var response = restTemplate.exchange(requestUrl.toString(), HttpMethod.GET, null, String.class);
System.out.println(response);
var requestUrl = new StringBuilder();
requestUrl
.append({{apiUrl}})
.append("/waInstance").append({{idInstance}})
.append("/getContacts/")
.append({{apiTokenInstance}});
var response = Unirest.get(requestUrl.toString())
.header("Content-Type", "application/json")
.asString();
System.out.println(response);
Sub GetContacts()
Dim url 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}}/GetContacts/{{apiTokenInstance}}"
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", url, False
http.Send
response = http.responseText
Debug.Print response
' Outputting the answer to the desired cell
Range("A1").Value = response
Set http = Nothing
End Sub