GET Method

The GET method is used to get contacts from the database. Users can retrieve all the contacts from their database using the following query. make sure to add header arguments while making API request.

http://yoursite.com/wp-json/gh/v3/contacts
{
    "contacts": {
        "1": {
            "data": {
                "email": "email@example.com",
                "first_name": "Jhon",
                "last_name": "Doe",
                "user_id": "2",
                "owner_id": "0",
                "optin_status": "0",
                "date_created": "2019-07-23 11:01:11",
                "ID": "2",
                "gravatar": "http:\/\/2.gravatar.com\/avatar\/eee931a46c043ad3b683e614b8c264f7?s=96&d=mm&r=g"
            },
            "meta": {
                "preferences_changed": "1563894071",
                "user_login": "test",
                "profile_picture": "http:\/\/2.gravatar.com\/avatar\/eee931a46c043ad3b683e614b8c264f7?s=96&d=mm&r=g",
                "primary_phone": "123456789",
                "company_name": "Groundhogg",
                "company_address": " 25 Lesmill Rd Unit D",
                "street_address_1": " 25 Lesmill Rd Unit D",
                "city": "North York",
                "postal_zip": " M3B 2T3",
                "region": "On",
                "country": "CA"
            },
            "tags": [
                11,
                9,
                2
            ],
            "files": []
        },
        "2": {
            ...
        },
        "3": {
            ...
        }
    }
}

Searching contacts

Users can search for specific contact details by adding the argument “q” while making a request. Apart from that users can also add an array of query arguments while making a request to filter results.

You can also perform this operation by setting “id_or_email” to user id of user and passing by_user_id = true.

http://yoursite.com/wp-json/gh/v3/contacts?q=jhon

This query will return all the contacts which contains “Jhon” string in any of the contact details

{
    "contacts": {
        "1": {
           "data": {
                "email": "email@example.com",
                "first_name": "Jhon",
                "last_name": "Doe",
                "user_id": "2",
                "owner_id": "0",
                "optin_status": "0",
                "date_created": "2019-07-23 11:01:11",
                "ID": "2",
                "gravatar": "http:\/\/2.gravatar.com\/avatar\/eee931a46c043ad3b683e614b8c264f7?s=96&d=mm&r=g"
            },
            "meta": {
                "preferences_changed": "1563894071",
                "user_login": "test",
                "profile_picture": "http:\/\/2.gravatar.com\/avatar\/eee931a46c043ad3b683e614b8c264f7?s=96&d=mm&r=g",
                "primary_phone": "123456789",
                "company_name": "Groundhogg",
                "company_address": " 25 Lesmill Rd Unit D",
                "street_address_1": " 25 Lesmill Rd Unit D",
                "city": "North York",
                "postal_zip": " M3B 2T3",
                "region": "On",
                "country": "CA"
            },
            "tags": [
                11,
                9,
                2
            ],
            "files": []
        },
        "2": {
            ...
        }
    }
}

List of contacts for select

Users can easily bound all the available contacts in dropdown by setting select parameter true. It will return a list of contact’s id and contact’s full name with the email address of a contact.

http://yoursite.com/wp-json/gh/v3/contacts?select=true
{
    "contacts":{
        "1":"Jhon Doe (Jhon@example.com)",
        "2":"Doe Jhon (doe@example.com)"
     },
    "status":"success"
}

List of contacts for select2

Users can also bound contacts inside a select-2 drop down by setting select2=true while making GET request. It will return select2 formate list for contact details.

http://yoursite.com/wp-json/gh/v3/contacts?select2=true
{
    "results": [
        {
            "id": "1",
            "text": "Jhon Doe (Jhon@example.com)"
        },
        {
            "id": "2",
            "text": "Doe Jhon (Doe@example.com)"
        }
    ],
    "more":false
} 
Was this article helpful to you? Yes No

How can we help?