Skip to content
Last updated

AddContact

Adds a contact to a client account.

Request Parameters

ParameterTypeDescriptionRequired
actionstring"AddContact"Required
clientidintRequired
firstnamestringOptional
lastnamestringOptional
companynamestringOptional
emailstringEmail address to identify the contact. This should be unique if the contact will be a sub-accountOptional
address1stringOptional
address2stringOptional
citystringOptional
statestringOptional
postcodestringOptional
countrystring2 character ISO country codeOptional
phonenumberstringOptional
tax_idstringOptional
email_preferences[general]boolShould the client receive general emailsOptional
email_preferences[product]boolShould the client receive product emailsOptional
email_preferences[domain]boolShould the client receive domain emailsOptional
email_preferences[invoice]boolShould the client receive invoice emailsOptional
email_preferences[support]boolShould the client receive support emailsOptional
email_preferences[affiliate]boolShould the client receive affiliate emailsOptional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
contactidintThe id of the newly added contact.

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' => 'AddContact',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'clientid' => '1',
            'firstname' => 'Jane',
            'lastname' => 'Doe',
            'email' => '[email protected]',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'AddContact';
$postData = array(
    'clientid' => '1',
    'firstname' => 'Jane',
    'lastname' => 'Doe',
    'email' => '[email protected]',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

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

Example Response JSON

{
    "result": "success",
    "contactid": "1"
}

Warning Responses

Warning responses are returned when using API functionality that has been removed or marked as deprecated. We suggest following any recommended actions in the warning to ensure future compatibility.

Possible warning messages include:

  • Sub Accounts are no longer supported. Please use AddUser and CreateClientInvite

Error Responses

Possible error condition responses include:

  • Client ID Not Found
  • Duplicate Email Address

Version History

VersionChangelog
1.0Initial Version
7.7Added tax_id parameter.
7.9Added affiliateemails parameter.
7.10Added email preferences parameters
8.0Removed sub-account functionality