Skip to content

GetContacts#

The method is aimed for getting a list of the current account contacts.

Request#

To get contacts, you have to execute a request at:

GET https://api.greenapi.com/waInstance{{idInstance}}/getContacts/{{apiTokenInstance}}

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

Response#

Response parameters#

Parameter Type Description
id string User or group chat Id
name string Contact name. Possible variants:
1) If the account is recorded in the phonebook, then we get the name from the book
2) If the account is not recorded in the phonebook, then we get the name from WhatsApp account
3) If the account is not recorded in the phone book and WhatsApp account name is not assigned, then we get an empty field
contactName string Contact name from the phone book
type string Contact type. Possible variants:
user - contact belongs to a user
group - contact is a group chat

Response body example#

[
    {
        "id": "11001234567@c.us",
        "name": "Ivan Petrov",
        "contactName": "Ivan Petorov Work",
        "type": "user"
    },
    {
        "id": "79001234568@c.us",
        "name": "Lyusya Sidorova",
        "contactName": "Liusya Sidorova Sewing Circle",
        "type": "user"
    },
    {
        "id": "79001234569-1479621234@g.us",
        "name": "My group",
        "contactName": "My Group",
        "type": "group"
    }
]

GetContacts errors#

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

HTTP code Error description Possible solutions
200 The getContacts method returns an empty array [] 1. Rescan the QR code.
2. Contact technical support.

Request examples#

import requests

url = "https://api.greenapi.com/waInstance{{idInstance}}/getContacts/{{apiTokenInstance}}"

payload = {}
headers= {}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
curl --location 'https://api.green-api.com/waInstance{{idInstance}}/getContacts/{{apiTokenInstance}}'
var restTemplate = new RestTemplate();
var requestUrl = new StringBuilder();
requestUrl
    .append("https://api.greenapi.com")
    .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("https://api.greenapi.com")
    .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 idInstance and apiTokenInstance values are available in your account, double brackets must be removed
    url = "https://api.greenapi.com/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