> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # AddProductMediaToChoices # Package: catalogV1 # Namespace: CatalogWriteApi # Method link: https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/add-product-media-to-choices.md ## Permission Scopes: Manage Products: SCOPE.DC-STORES.MANAGE-PRODUCTS ## Introduction Links media items that are already associated with a specific product to a choice within the same product. Media items can only be set for choices within one option at a time - e.g., if you set media items for some or all of the choices within the Colors option (blue, green, and red), you won't be able to also assign media items to choices within the Size option (S, M, and L). To remove all existing media items, call the [Remove Product Media From Choices](https://dev.wix.com/api/rest/wix-stores/catalog/products/remove-product-media-from-choices) endpoint. --- ## REST API ### Schema ``` Method: addProductMediaToChoices Description: Links media items that are already associated with a specific product to a choice within the same product. Media items can only be set for choices within one option at a time - e.g., if you set media items for some or all of the choices within the Colors option (blue, green, and red), you won't be able to also assign media items to choices within the Size option (S, M, and L). To remove all existing media items, call the [Remove Product Media From Choices](https://dev.wix.com/api/rest/wix-stores/catalog/products/remove-product-media-from-choices) endpoint. URL: https://www.wixapis.com/stores/v1/products/{id}/choices/media Method: PATCH # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: media.option, media.choice Method parameters: param name: media | type: array | description: Product media items and the choices to add the media to. - name: option | type: string | description: Option name. | required: true - name: choice | type: string | description: Choice name. | required: true - name: mediaIds | type: array | description: Media GUIDs (available via the Query Product endpoint). Return type: AddProductMediaToChoicesResponse EMPTY-OBJECT {} ``` ### Examples ### Add 2 media items to an option choice ```curl curl -X POST \ 'https://www.wixapis.com/stores/v1/products/1044e7e4-37d1-0705-c5b3-623baae212fd/choices/media' \ -H 'Content-Type: application/json' \ -H 'Authorization: ' \ -d '{ "media": [ { "option": "Color", "choice": "blue", "mediaIds": [ "9cc22d8b8d5244aba9ed73fb1783fc26.jpg", "fljseif3l4ij3l4ijl3r32fwfwf23234.jpg" ] } ] }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.catalogV1.CatalogWriteApi.addProductMediaToChoices(_id, media) Description: Links media items that are already associated with a specific product to a choice within the same product. Media items can only be set for choices within one option at a time - e.g., if you set media items for some or all of the choices within the Colors option (blue, green, and red), you won't be able to also assign media items to choices within the Size option (S, M, and L). To remove all existing media items, call the [Remove Product Media From Choices](https://dev.wix.com/api/rest/wix-stores/catalog/products/remove-product-media-from-choices) endpoint. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: _id, media.option, media.choice, media Method parameters: param name: _id | type: string | description: Product GUID. | required: true param name: media | type: array | description: Product media items and the choices to add the media to. | required: true - name: option | type: string | description: Option name. | required: true - name: choice | type: string | description: Choice name. | required: true - name: mediaIds | type: array | description: Media GUIDs (available via the Query Product endpoint). Return type: PROMISE EMPTY-OBJECT {} ``` ### Examples ### Add media items to product options ```javascript /************************************** * Backend code - products.web.js/ts * **************************************/ import { Permissions, webMethod } from '@wix/web-methods'; import { products } from '@wix/stores'; export const addProductMediaToChoices = webMethod(Permissions.Anyone, (_id, media) => { return products.addProductMediaToChoices(_id, media); }); /************* * Page code * *************/ import { addProductMediaToChoices } from 'backend/products.web'; // ... const _id = ...; // get product ID const mediaIds = ["wix:image://v1/1a11a1_..._1a~mv2.jpg/1a11a1_..._1a~mv2.jpg"]; const option = "Color"; const choice = "Blue"; const media = [{ mediaIds, option, choice }]; addProductMediaToChoices(_id, media); ``` ### addProductMediaToChoices (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { products } from '@wix/stores'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { products }, // Include the auth strategy and host as relevant }); async function addProductMediaToChoices(_id,media) { const response = await myWixClient.products.addProductMediaToChoices(_id,media); }; ``` ---