Jump to content

Is there a limit on length of invoices through API?


Recommended Posts

I've just noticed that when creating invoices through the API, it seems that only a maximum of 331 invoice items can be added in a CreateInvoice API call.

We have a certain client who each month has an invoice with more than 331 items. When testing importing several months worth of these invoices, all of them are truncated at 331 line items despite the full set of line items being present in the request. It doesn't seem to be a restriction in WHMCS itself, as I'm able to add further line items through the UI or by using the UpdateInvoice API.

Is this expected behaviour for the CreateInvoice API, and is this limit documented anywhere and I just missed seeing it?

Link to comment
Share on other sites

1 hour ago, steph.hope said:

I've just noticed that when creating invoices through the API, it seems that only a maximum of 331 invoice items can be added in a CreateInvoice API call.

We have a certain client who each month has an invoice with more than 331 items. When testing importing several months worth of these invoices, all of them are truncated at 331 line items despite the full set of line items being present in the request. It doesn't seem to be a restriction in WHMCS itself, as I'm able to add further line items through the UI or by using the UpdateInvoice API.

Is this expected behaviour for the CreateInvoice API, and is this limit documented anywhere and I just missed seeing it?

I have no idea, but I don't think the developers would had addended a fixed limit that ends strangely at 331.

This is more likely a limit or timeout on your installation. PHP has a timeout; default is 30 seconds. The process timeouts at that point or the memory is exhausted. Did you check the server logs or WHMCS modules to see if there was an error after running that API call with that many invoices? I suspect this is your issue, not a limit per say on the API call.

I don't think it's a clever idea to create that many items on one single request. Why don't you create one call per invoice to avoid the issues? This is usually what people would, one API call per action. Not try to add hundreds of actions on one single call which is just asking for troubles.

Link to comment
Share on other sites

There is no limit. I just created an invoice with 401 items (attached) using the code below. As @yggdrasil said, it's your PHP hitting timeout.

<?

$postData = array(
  'userid' => '1',
  'status' => 'Unpaid',
  'sendinvoice' => '1',
  'paymentmethod' => 'mailin',
  'taxrate' => '10.00',
  'date' => '2020-11-12',
  'duedate' => '2020-11-12',
  'autoapplycredit' => '0',
);

for ($x = 0; $x <= 400; $x++)
{
  $postData['itemdescription' . $x] = 'Item ' . $x;
  $postData['itemamount' . $x] = '1';
  $postData['itemtaxed' . $x] = true;
}

$results = localAPI('CreateInvoice', $postData);

 

Invoice-PROFORMA-2160.pdf

Link to comment
Share on other sites

Cool, thanks for the info about the timeout, I'll see what I can do to fix that.

14 hours ago, yggdrasil said:

 Why don't you create one call per invoice to avoid the issues?

That is one call per invoice, it's just a ridiculously large invoice 😬

Edited by steph.hope
Link to comment
Share on other sites

9 hours ago, steph.hope said:

Cool, thanks for the info about the timeout, I'll see what I can do to fix that.

That is one call per invoice, it's just a ridiculously large invoice 😬

I see, gosh what a huge invoice that must be with that many items. Is it even readable with hundreds of items...? 😅

But this does make me curious how many items can the API handle on one invoice with a default PHP 7 installation (not changes). Not that I need this right now but I do want to be able to bill hundreds of items in one invoice as well in some future.

Link to comment
Share on other sites

I think you can safely create unlimited lines via API - for sure more than 5k. The real problem is when you press "Save Changes" as you hit your PHP max_input_vars limit. 5k invoice items x 3 inputs each (description, amount, taxed) = 15k input vars + 1 (the "Save Changes" button). This leads to very unpleasent results as PHP simply ignores the last 14k values with no error on screen. In other words you can apply changes only to the first 332 invoice items. The remaining 14668 items can't be updated from WHMCS interface.

A more common scenario where this problem occurs is Domain Pricing (and the old Tax Rules page). I had customers failing to update TLD options and "Auto registration" as they had a too many extensions. Every TLD has 6 fields meaning you can reach the 1000 max_input_vars limit with 166 domains. Having 200 TLD means that the last 34 items can't be updated.

@steph.hope make sure to increase your max_input_vars in case you are issuing invoices with more than 332 items.

Edited by Kian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated