WHMCS API Update CustomFields

A big problem with WHMCS is that you don’t have any API to manage customfields. With this API you can update all clients, products and support custom fields.

You can use it as a standard WHMCS API. You may want to use it with internal API function. In this case WHMCS documentation is helpful so no more explanations are required. Keep in mind that due to the way WHMCS handles API permissions, you will only be able to use this as internal API.

To use it you have to upload the updatecustomfields.php (all lowercase) into the /includes/api whmcs folder and it’s done.

Parameters

ParameterTypeDescriptionRequired
relidintThe ID of the related item you want to get the custom fields forRequired
typestringSupports client, product or support. defaults to clientOptional
customfieldint or stringUse either the id of the customfield or its nameRequired
valuestringThe new value for the custom field, can be emptyOptional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
messagestringThe result message

 

Example request (CURL)

Given the recent changes in WHMCS custom API work only with the Local API function.

Example Request (Local API)

$command = 'UpdateCustomFields';
$postData = array(
    'relid' => 1,
    'customfield' => 12,
    'value' => 'newvalue',
);
$adminUsername = 'ADMIN_USERNAME';

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

Example Response

Array ( 
	[result] => success,
	[message] => Custom field with id # has been updated with the value: newvalue,
	)

Error Responses

Error response codes are:

  • The relid is undefined
  • The type you selected does not exists. Please check
  • The customfield is undefined
  • The customfield could not be found. Please check the ‘customfield’ and ‘type’ parameters
  • A client with id # does not exists
  • A product with id # does not exists
  • This product does not own this custom field
  • A ticket with id # does not exists
  • This support department does not own this custom field

Got questions or problems? Contact us or comment, we’ll be happy to help.

WHMCS API Get CustomFields

A big problem with WHMCS is that you don’t have any API to manage customfields. With this API you can get all clients, products or support custom fields.

You can use it as a standard WHMCS API. You may want to use it with internal API function. In this case WHMCS documentation is helpful so no more explanations are required. Keep in mind that due to the way WHMCS handles API permissions, you will only be able to use this as internal API.

To use it you have to upload the getcustomfields.php (all lowercase) into the /includes/api whmcs folder and it’s done.

Parameters

ParameterTypeDescriptionRequired
relidintThe ID of the related item you want to get the custom fields forRequired
typestringSupports client, product or support. defaults to clientOptional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
fieldnameArrayAn array with all the data using the name of the field as the key of the Array
fieldidArrayAn array with all the data using the id of the field as the key of the Array

 

Example request (CURL)

Given the recent changes in WHMCS custom API work only with the Local API function.

Example Request (Local API)

$command = 'GetCustomFields';
$postData = array(
    'relid' => 1,
);
$adminUsername = 'ADMIN_USERNAME';

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

Example Response

Array ( 
	[result] => success,
        [1] => Array
        (
            [id] => 1
            [fieldname] => custom field name
            [fieldtype] => text
            [description] => description
            [fieldoptions] => 
            [regexpr] =>
            [adminonly] => 
            [required] => 
            [showorder] => 
            [showinvoice] => 
            [value] => value
            [created_at] => 2019-01-19 18:00:00
            [updated_at] => 2019-01-20 11:16:43
        )

        [custom field name] => Array
        (
            [id] => 1
            [fieldname] => custom field name
            [fieldtype] => text
            [description] => description
            [fieldoptions] => 
            [regexpr] =>
            [adminonly] => 
            [required] => 
            [showorder] => 
            [showinvoice] => 
            [value] => value
            [created_at] => 2019-01-19 18:00:00
            [updated_at] => 2019-01-20 11:16:43
        )
	)

Error Responses

Error response codes are:

  • The relid is undefined
  • The type you selected does not exists. Please check
  • No custom fields were found

Got questions or problems? Contact us or comment, we’ll be happy to help.

WHMCS API CreateToDo

For some reasons WHMCS has a UpdateToDoItem to be able to update a todo as well as GetToDoList and GetToDoItemStatuses to manage todo using API, but not a CreateToDo API function.

Because of this reason we just decided to create a custom API to create a ToDo record. Read more

How to create custom API in WHMCS

In this article we’ll see how to create custom API in WHMCS. The reason I’m writing this is because the information you can find on the net are outdated, and since now we are at WHMCS, there is the need for an update.

WHMCS is a great piece of software. In certain cases though you just can’t do something. Their documentation is surely not helping since not everything is documented, and looking at the code to figure out how things work is not really an option thanks to the file encryption. Read more