How to get actual product images out of ExactOnline using the API and Picqer-Exact-Php-Client

336 views Asked by At

I am using the picqer exact client to retrieve product data from exactonline. I would like to get the actual image out of eol. Following code indeed retrieves all 1700+ active products in eol:

   $conn = new \Picqer\Financials\Exact\BulkItem($connection);
   $today = date('Y-m-d');
   $items = $conn->filter("StartDate le datetime'{$today}T23:59:59' and (EndDate ge datetime'{$today}T00:00:00' or EndDate eq null)", '', 'ID,Barcode, Code, Description, ExtraDescription, ItemGroupCode, ItemGroupDescription, PictureName, PictureUrl, SalesVatCode, SalesVatCodeDescription, StandardSalesPrice, Stock', ['$top' => 10000]);

I get PictureUrl but the url is only usable when a user is logged in to eol. It cannot be used in the API.

Any ideas how to get the actual image using the API?

Note: StartDate and Endate in the filter is my hack to get only 'active' products. There may be a more elegant filter to achieve the same.

2

There are 2 answers

1
Punchcard Coder On BEST ANSWER

The eol docs for another endpoint mention to add "&Download=1" for fetching the actual attachment instead of an url (https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=DocumentsDocumentAttachments). Searching the picqer code for "Download=1" led to the solution. Too bad the picqer library is rather sparsely documented - could have saved me hours.

This gets the actual product picture out of exactonline for active products:

$conn = new \Picqer\Financials\Exact\BulkItem($connection);
$today = date('Y-m-d');
$items = $conn->filter("StartDate le datetime'{$today}T23:59:59' and (EndDate ge datetime'{$today}T00:00:00' or EndDate eq null)", '', 'ID,Barcode, Code, Description, ExtraDescription, ItemGroupCode, ItemGroupDescription, PictureName, PictureUrl, SalesVatCode, SalesVatCodeDescription, StandardSalesPrice, Stock', ['$top' => 10000]);
foreach ($items as $item){
   $picture = $item->download();
   // do something with $picture, for instance imagecreatefromstring($picture)
};
3
Guido Leenders On

See https://forums.invantive.com/t/retrieve-blob-of-image-url-on-exact-online/39/2. Just retrieve the BLOB over the secure channel.