# Webservice API / retrieve documents related to products

**URL:** <https://www.dolibarr.org/forum/t/webservice-api-retrieve-documents-related-to-products/24237>\
**Category:** Using my Dolibarr\
**Tags:** Issue, API\
**Created:** [September 1, 2023, 12:01pm UTC](https://www.dolibarr.org/forum/t/webservice-api-retrieve-documents-related-to-products/24237 "2023-09-01T12:01:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eurya](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/e/e0b2c6/32.png) [@Eurya](https://www.dolibarr.org/forum/u/Eurya)\
**Post date:** [September 1, 2023, 12:01pm UTC](https://www.dolibarr.org/forum/t/webservice-api-retrieve-documents-related-to-products/24237/1 "2023-09-01T12:01:37Z")

</div>

Hello,

I encountered an issue while trying to retrieve attached files of a product via the API, specifically within the `getDocumentsListByElement` function of `api_documents.class.php`.

The `$upload_dir` generated was incorrect, resulting in a 404 error even though a file was indeed attached to the product.

In my case, the generated `$upload_dir` was `htdocs/documents/produit/bougeoir-1/`, whereas the actual path to the product’s file on the server was `htdocs/documents/produit/0/9/390/photos/`.

The `$upload_dir` is generated by this line of code:  
$upload\_dir = $conf-\>product-\>multidir\_output[$object-\>entity].‘/’.get\_exdir(0, 0, 0, 1, $object, ‘product’);

It appears that the `get_exdir` function is not generating the intermediate subdirectories correctly.

As a temporary patch, I modified the code to generate the subdirectories based on the product’s ID:  
$id = $object-\>id;  
$upload\_dir = $conf-\>product-\>multidir\_output[$object-\>entity].‘/’.substr($id, -1).‘/’.substr($id, -2, 1).‘/’.$id.‘/photos’;

This modification successfully generates the correct path for product IDs up to 999. For products with IDs greater than 999, the code would need to be adjusted accordingly.

I wanted to share this issue and my temporary patch with the community in case anyone else encounters the same problem. Additionally, I would like to ask if this could be due to a configuration issue on my end, or if it is a known bug that others have encountered and will be addressed in a future update.

Thank you for your help and support!

Dolibarr version used: 17.0.0
