Skip to content
Last updated

GetEmailTemplates

Obtain a list of email templates from the system

Request Parameters

ParameterTypeDescriptionRequired
actionstring"GetEmailTemplates"Required
typestringThe type of email template to retrieveOptional
languagestringThe language of the email template to retrieve, if none provided will return default language templates.Optional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
totalresultsintThe total number of results returned
emailtemplatesarrayThe email templates 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' => 'GetEmailTemplates',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'type' => 'general',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'GetEmailTemplates';
$postData = array(
    'type' => 'general',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

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

Example Response JSON

{
    "result": "success",
    "totalresults": "2",
    "emailtemplates[emailtemplate][0][id]": "38",
    "emailtemplates[emailtemplate][0][name]": "Automated Password Reset",
    "emailtemplates[emailtemplate][0][subject]": "Your new password for {$company_name}",
    "emailtemplates[emailtemplate][0][custom]": "0",
    "emailtemplates[emailtemplate][1][id]": "64",
    "emailtemplates[emailtemplate][1][name]": "Client Email Address Verification",
    "emailtemplates[emailtemplate][1][subject]": "Confirm Your Registration",
    "emailtemplates[emailtemplate][1][custom]": "0"
}

Version History

VersionChangelog
1.0Initial Version