Question

I'm having troubles using the catalogProductAttributeMediaGalleryManagementV1 API rest for manage the products images in a multiple storeView project.

The main problem, is when I use the

POST /V1/products/{sku}/media 

for upload an image, it does alright for my default store but in the others the attributes 'label', 'position' and others stays on NULL value. So on the list products page, on my default storeView looks good but in the others the images are not showed, but if you go inside the product the image exists. I figured out the problem is because position is NULL, on the list page Magento doesn't know what image has to display.

This is the image result on my default storeView:

{
   "id": 3492,
    "media_type": "image",
    "label": null,
    "position": 0,
    "disabled": false,
    "types": [
        "image",
        "small_image",
        "thumbnail"
     ],
    "file": "/I/1/I16_264_10.jpg"
}

And this is on any other storeView:

{
    "id": 3492,
    "media_type": "image",
    "label": null,
    "position": null,
    "disabled": null,
    "types": [],
    "file": "/I/1/I16_264_10.jpg"
}

I know you can use API rest writing the storeView code after 'rest' segment for use only this storeview, like:

rest/es/V1/products/{sku}/media
rest/en/V1/products/{sku}/media

Playing with db I figured out that if I put storeView 0 which is "admin" it works all! So I tried to do that query:

rest/admin/V1/products/{sku}/media

But says route doesn't match. Why? If I try with the others storeViews code it works!

I tried to extend the code that magento uses and I really don't know what is happening. And I don't know neither how the API manages this code you can write after the 'rest' segment... I tried to change the code, when he gets the product, I put added the storeView code 0 (it's admin) and do all stuff, but I think then when it saves the product, it does with default storeView... so I couldn't fix anything.

I have the ultimate alternative which is use:

PUT /V1/products/{sku}/media/{entryId}

For every storeView after used POST, and changing the value of position and label... But we'll have a extremely issue of performance here...

or just use for every storeView the POST...

Was it helpful?

Solution

Use the all keyword in your API call if you want your value to affect all stores.

rest/all/V1/products/{sku}/media

Review Magento's documentation regarding this below. http://devdocs.magento.com/guides/v2.1/rest/rest_endpoints.html

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top