steph.hope Posted November 12, 2020 Share Posted November 12, 2020 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? 0 Quote Link to comment Share on other sites More sharing options...
yggdrasil Posted November 12, 2020 Share Posted November 12, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted November 12, 2020 Share Posted November 12, 2020 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 0 Quote Link to comment Share on other sites More sharing options...
steph.hope Posted November 12, 2020 Author Share Posted November 12, 2020 (edited) 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 November 12, 2020 by steph.hope 0 Quote Link to comment Share on other sites More sharing options...
steph.hope Posted November 12, 2020 Author Share Posted November 12, 2020 Turns out the issue wasn't a timeout but instead : Quote PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted November 13, 2020 Share Posted November 13, 2020 json_encode your POST in one input variable. 0 Quote Link to comment Share on other sites More sharing options...
yggdrasil Posted November 13, 2020 Share Posted November 13, 2020 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. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted November 13, 2020 Share Posted November 13, 2020 (edited) 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 November 13, 2020 by Kian 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.