Skip to content
Last updated

GetContacts

Obtain the Client Contacts that match passed criteria

Request Parameters

ParameterTypeDescriptionRequired
actionstring"GetContacts"Required
limitstartintThe offset for the returned log data (default: 0)Optional
limitnumintThe number of records to return (default: 25)Optional
useridintFind contacts for a specific client idOptional
firstnamestringFind contacts with a specific first nameOptional
lastnamestringFind contacts with a specific last nameOptional
companynamestringFind contacts with a specific company nameOptional
emailstringFind contacts with a specific email addressOptional
address1stringFind contacts with a specific address line 1Optional
address2stringFind contacts with a specific address line 2Optional
citystringFind contacts with a specific cityOptional
statestringFind contacts with a specific stateOptional
postcodestringFind contacts with a specific post/zip codeOptional
countrystringFind contacts with a specific countryOptional
phonenumberstringFind contacts with a specific phone numberOptional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
totalresultsintThe total number of results available
startnumberintThe starting number for the returned results
numreturnedintThe number of results returned
contactsarrayThe contact entries returned

Example Request (CURL)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'GetContacts',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'userid' => '1',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'GetContacts';
$postData = array(
    'userid' => '1',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

Example Response JSON

{
    "result": "success",
    "totalresults": 1,
    "startnumber": 0,
    "numreturned": 1,
    "contacts": {
        "contact": [
            {
                "id": 1,
                "userid": 1,
                "firstname": "Test",
                "lastname": "Contact",
                "email": "[email protected]",
                "address1": "404 Street Not Found",
                "address2": "",
                "city": "Test",
                "state": "Test",
                "postcode": "TE5 5ST",
                "country": "GB",
                "phonenumber": "",
                "domainemails": true,
                "generalemails": true,
                "invoiceemails": true,
                "productemails": true,
                "supportemails": true,
                "affiliateemails": true,
                "created_at": "0000-00-00 00:00:00",
                "updated_at": "0000-00-00 00:00:00"
            }
        ]
    }
}

Version History

VersionChangelog
1.0Initial Version
8.0Removed sub-account functionality