Jump to content

Update Product Image Position via WebService API in PrestaShop 8.2.3 without Re-Upload (Possible?)


Recommended Posts

Hi PrestaShop Community,

I'm developing an external app that integrates with PrestaShop 8.2.3 via WebService API to replace product images while maintaining the original position in the image gallery (e.g., replace image at position 3 without it going to the end).

Current Setup: - PrestaShop version: 8.2.3 (localhost XAMPP setup).

- API key with full permissions for products (GET/PUT) and images (GET/POST/DELETE).

- Example: Product ID 2 has images [2, 30, 33, 36, 37, 38, 39, 40]. I want to replace ID 33 (position 3) with a new image (ID 41).

What I've Tried (based on docs and forums):

1. DELETE /images/products/2/33 (success, HTTP 200).

2. POST /images/products/2 (new image ID 41 uploaded, but at last position).

3. PUT /products/2 with minimal XML including <associations><images> in desired order (e.g., <image><id>2</id></image><image><id>30</id></image><image><id>41</id></image>...), id, price, name, id_category_default. - Response: HTTP 200, but position ignored—new image still at end (order: 2, 30, 36, 37, 38, 39, 40, 41).

4. Retries with sleep(10) and re-fetch image list before PUT—still fails.

5. Full re-upload method (delete all, re-upload in order)—works but wasteful for bandwidth/time (app for multiple users).

Question:

Is there a way to update ps_image.position via API without re-uploading all images? (e.g., direct PUT on image resource or hidden param in associations/images?)

Why is associations/images order ignored for new images? Any bug in 8.2.3?

Any workaround (e.g., custom header, schema=blank, or override without DB access)?

Similar thread: https://www.prestashop.com/forums/topic/1041234-update-product-images-position-and-not-image-via-webservice-api/ (from 2022, no resolution).

Thanks for any help/suggestions! Code snippets or XML examples appreciated.

Link to comment
Share on other sites

Hello!
I want to share my opinion on this topic!

I'm not a super-duper expert on Prestashop but in the past I had some problems with the webservice's api.
My workaround was pretty simple and opened a new world for me: I created a custom endpoint.

In the documentation there is a section about this.
You just create a new endpoint (ex. /api/extended_product/ ) by creating a custom module and you extend the logic of the product webservice api by creating some specific setter and getter.
You might want, for example, to add a field "image_order" inside the association/images  and then process those data with a simple query on the db!

Hope this helps a bit :)

Link to comment
Share on other sites

Hi Matteo,

@MatteoIommiThank you for your input!

I understand your solution of creating a custom endpoint inside a module to handle image order. However, for my use case, I need a solution that works fully via API and is automatable across multiple stores.

Since the standard PrestaShop WebService API ignores the <associations><images> order for newly uploaded images, I cannot rely on manually changing anything inside each store. Full re-uploading of all images works, but it’s too bandwidth-heavy and inefficient for multiple users.

So, I wanted to ask:

Is there any way to update ps_image.position via the standard WebService API without creating a custom module or directly accessing the database?

Or is the custom module endpoint approach the only viable solution for automating image replacement while keeping the position intact?

I just want to confirm whether any pure API solution exists before going down the custom module route.

Thanks in advance for any clarification!

Link to comment
Share on other sites

  • razaro changed the title to Update Product Image Position via WebService API in PrestaShop 8.2.3 without Re-Upload (Possible?)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...