API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

How to use/format parameters for API functions ? Example: invoice_FindByDateInterval


Please forgive me, I'm just a beginner...

I'm trying to write some PHP script. I need to list invoices from one date to another, using the API function Invoice_FindByDateInterval. I have found this "documentation":

Returns handles for invoices in a given interval of days.
Parameters: first: First day in interval. last: Last day in interval.

Next, I entered the below in a PHP script:

$invoices = "";
$invoiceHandles = $client->Invoice_FindByDateInterval('first' => $date_beg, 'last' => $date_end)->Invoice_FindByDateIntervalResult->InvoiceHandle;
$invoiceDataObjects = $client->Invoice_GetDataArray(array('entityHandles' => $invoiceHandles))->Invoice_GetDataArrayResult->InvoiceData;
foreach ($invoiceDataObjects as $i => $invoiceData) {
  $invdate = $invoiceData->Date;

and so on...

But... I don't get any response. I suspect that is has something to do with the parameters ("first" and "last") I'm feeding to the function.
Any help to clean up this code is highly appreciated. Thank you in advance.

created Jun 15, 2015 by thomas.k
0% Accept Rate
Q 2 A 1 C 3

1 Answer

Hi Thomas

Try to have a look here for documentation:




Invoice_FindByDateInterval is booked invoices.

If you're looking for drafts you should use CurrentInvoice_FindByDateInterval


When setting up please make sure that you have actual data within the timespan you're searching.


Perhaps some of the other forum users might want to give their 5c with regards to code clean-up.
answered Jun 22, 2015 by olej
Hi Ole,

Thank you very much for trying to point me in the right direction. Your help is much appreciated.  

But, I have already looked at this so-called "documentation". To be honest, I don't se it as very much documentation. Maybe, one day, when I get used to it, it may be of help. As it is now, it does not provide much help.

Anyway, I have found two errors in my code, and now it works :-)

$invoiceHandles = $client->Invoice_FindByDateInterval('first' => $date_beg, 'last' => $date_end)->Invoice_FindByDateIntervalResult->InvoiceHandle;

The parameters for first and last should be entered as:
... Invoice_FindByDateInterval(array('first' => $date_beg, 'last' => $date_end)) ...

The syntax for first and last dates must be very strict in conformacy with the datetime format used by e-conomics: yyyy-mm-ddThh:mm:ss

So, I ended up with this little PHP code snippet:
$date_end = date("Y-m-d")."T23:59:59";
(and something similar for the start date)

I had the impression that the time-part could be omitted and that the capital T between the date-part and the time-part could be omitted as well. At this point, the documentation could be much better, simply by stating correct formats for, say, datetime values.

But, as said, after making these small corrections, my code worked flawlessly. And who knows, next time I need to use the "documentation", it may be of better value to me.

Again, thank you you very much for your help.

Visma e-conomic A/S