Skip to content
Last updated

UpdateInvoice

Update an invoice using the provided parameters.

Request Parameters

ParameterTypeDescriptionRequired
actionstring"UpdateInvoice"Required
invoiceidintThe ID of the invoice to update.Required
statusstringThe status of the invoice being updated.Optional
paymentmethodstringThe payment method of the invoice in system format.Optional
taxratefloatThe first-level tax rate to apply to the invoice to override the system default.Optional
taxrate2floatThe second-level tax rate to apply to the invoice to override the system default.Optional
creditfloatUpdate the credit applied to the invoice.Optional
datestringThe date that the invoice should show as its creation date. Format: YYYY-mm-ddOptional
duedatestringThe due date of the invoice. Format: YYYY-mm-ddOptional
datepaidstringThe date paid for the invoice. Format: YYYY-mm-ddOptional
notesstringThe notes to appear on the invoice.Optional
itemdescriptionstring[]An array of lineItemId => Description of items to change. The lineItemId is the ID of the item from the GetInvoice API command.Optional
itemamountfloat[]An array of lineItemId => amount of items to change. Required if itemdescription is provided.Optional
itemtaxedbool[]An array of lineItemId => taxed of items to change Required if itemdescription is provided.Optional
newitemdescriptionstring[]The line items description. This should be a numerically indexed array of new line item descriptions.Optional
newitemamountfloat[]The line items amount. This should be a numerically indexed array of new line item amounts.Optional
newitemtaxedbool[]Should the new line items be taxed. This should be a numerically indexed array of new line item taxed values.Optional
deletelineidsint[]An array of line item IDs to remove from the invoice. This is the ID of the line item, from GetInvoice API command.Optional
publishboolWhether to publish the invoice.Optional
publishandsendemailboolWhether to publish and email the invoice.Optional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error
invoiceidintThe ID of the update invoice.

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' => 'UpdateInvoice',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'invoiceid' => '1',
            'status' => 'Unpaid',
            'itemdescription' => array(13 => 'Sample Updated Invoice Item'),
            'itemamount' => array(13 => 16.95),
            'itemtaxed' => array(13 => false),
            'newitemdescription' => array(0 => 'New Line Item 1', 1 => 'New Line Item 2'),
            'newitemamount' => array(0 => 10.00, 1 => 2.95),
            'newitemtaxed' => array(0 => true, 1 => false),
            'deletelineids' => array(11, 12),
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'UpdateInvoice';
$postData = array(
    'invoiceid' => '1',
    'status' => 'Unpaid',
    'itemdescription' => array(13 => 'Sample Updated Invoice Item'),
    'itemamount' => array(13 => 16.95),
    'itemtaxed' => array(13 => false),
    'newitemdescription' => array(0 => 'New Line Item 1', 1 => 'New Line Item 2'),
    'newitemamount' => array(0 => 10.00, 1 => 2.95),
    'newitemtaxed' => array(0 => true, 1 => false),
    'deletelineids' => array(11, 12),
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

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

Example Response JSON

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

Error Responses

Possible error condition responses include:

  • Invoice ID Not Found
  • Invoice must be in Draft status to be published
  • Missing Variables: itemdescription, itemamount and itemtaxed are required for each item being changed
  • Invalid status $status

Version History

VersionChangelog
1.0Initial Version
7.8Removed total, tax, tax2 and subtotal parameters. Adjust invoice items and tax rates to adjust these.