TBroMEM Posted 18 hours ago Share Posted 18 hours ago (edited) I am using the following localAPI request in a hook (excerpt) to determine number of invoices matching the request (e.g. # unpaid for a defined client). $clientid = $vars['params']['userid']; // triggered from premodulerenew hook $invoicecount = 1; $command = 'GetInvoices'; $values = array( 'userid' => $clientid, 'status' => 'Unpaid' ); $getClientInvoices = localAPI($command, $postData); if ($getClientInvoices['result'] == 'success') { $invoicecount = $getClientInvoices['numreturned']; } if ($invoicecount >= 1) { logActivity('Service renewal will be aborted for client ' . $clientid . '. It is not qualified because it has ' . $invoicecount . ' unpaid invoices - by hook_send_renewal_notice_toadmin...'); } The $clientid listed in the logactivity matches the clientid passed to the LocalAPI ('userid' => $clientid), but it first returned over a 1103 as totalresult in the response. So, I thought I would switch to numreturned in the response, and it went to 25 (which is default for number to return) 1103 from $invoicecount from response.totalresults Service renewal will be aborted for client 585. It is not qualified because it has 1103 unpaid invoices - by hook_send_renewal_notice_toadmin... 25 from $invoicecount using response.numreturned Service renewal will be aborted for client 585. It is not qualified because it has 25 unpaid invoices - by hook_send_renewal_notice_toadmin... 585 is the correct clientid as reported in the logactivity so how in the world is it reporting 1103 and 25? There only 2 invoices recorded for the client and only 1 is unpaid. Edited 18 hours ago by TBroMEM minor code revision 0 Quote Link to comment Share on other sites More sharing options...
towhiddex Posted 18 hours ago Share Posted 18 hours ago your API call isn’t using the filter array you think it is, and you’re reading the wrong field from the response. 1103 = totalresults for all unpaid invoices (because filters weren’t applied). 25 = numreturned default page size, with no limitnum specified. $clientid = (int) $vars['params']['userid']; $command = 'GetInvoices'; $postData = array( 'userid' => $clientid, 'status' => 'Unpaid', 'limitstart' => 0, 'limitnum' => 3000, ); $getClientInvoices = localAPI($command, $postData); // , $adminuser if needed $invoicecount = 0; if ($getClientInvoices['result'] === 'success') { $invoicecount = (int) $getClientInvoices['totalresults']; } if ($invoicecount >= 1) { logActivity( 'Service renewal will be aborted for client ' . $clientid . '. It is not qualified because it has ' . $invoicecount . ' unpaid invoices - by hook_send_renewal_notice_toadmin...' ); } 0 Quote Link to comment Share on other sites More sharing options...
TBroMEM Posted 17 hours ago Author Share Posted 17 hours ago (edited) It is acting like it is not recognizing the client id and returning for all client invoices matching unpaid. not sure why. Will be declaring $clientid as int and then passing it in. We'll see. $client = $vars['params']['userid']; // triggered from premodulerenew hook $clientid = (int) $client; The module params documentation indicates userid is Id from tblclients.id, which indicates in schema it is already an int. The curious thing is, I pulled same code from another hook that used same localAPI for GetInvoices and it had no issues at all. Edited 17 hours ago by TBroMEM additional info 0 Quote Link to comment Share on other sites More sharing options...
TBroMEM Posted 13 hours ago Author Share Posted 13 hours ago Even with setting the $clientid as integer and using that in the API request, it still acts like no clientid reference is supplied. What am I missing. 0 Quote Link to comment Share on other sites More sharing options...
TBroMEM Posted 12 hours ago Author Share Posted 12 hours ago @towhiddex The one thing you missed is that I did pass in the $clientid (params userid assignment). The client in question had no Unpaid invoices (as defined in the postdata array. When I tested similar using postman request to our production (there are limits in our dev) it returned anticipated results of 0 for totalresults and numreturned which is what I am anticipating. I am not concerned about limitnum because the default return of 25 would be fine. All I need to evaluate is whether it is 0 or >=1. 0 Quote Link to comment Share on other sites More sharing options...
TBroMEM Posted 11 hours ago Author Share Posted 11 hours ago Here are some screenshots. One shows view of client record invoices (there are only two invoices, and none are unpaid) The other reflects what was captured from the declared/captured values (25 for num of invoices is from numreturned). 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.