• Resolved Rita Alamino

    (@ritaalamino)


    Hi, I am trying to upload multiple images via api rest. But I did not get how to upload the images, get their ID to insert via meta data.

    Which order should I upload? It is a lot of images.
    How can I get images ID after upload?
    How can I prepare the JSON?
    Is there a page I need to configure at woocomerce php in order for this work?

    {‘regular_price’: ‘21.1’, ‘image’: {‘src’: ‘https://www.alphabroder.com/images/alp/prodDetail/01940e1_04_p.jpg’}, ‘woo_variation_gallery_images’: [{‘src’: ‘https://www.alphabroder.com/images/alp/prodDetail/01940e1_04_p.jpg’}, {‘src’: ‘ https://www.alphabroder.com/images/alp/prodGallery/01940e1_04_g.jpg’}, {‘src’: ‘ https://www.alphabroder.com/images/alp/prodDetail/01940e1_04_p.jpg’}, {‘src’: ‘ https://www.alphabroder.com/images/alp/backDetail/01940e1_bk_04_p.jpg’}, {‘src’: ‘ https://www.alphabroder.com/images/alp/sideDetail/01940e1_sd_04_p.jpg’}], ‘attributes’: [{‘id’: 4, ‘name’: ‘Size’, ‘option’: ‘M’}, {‘id’: 3, ‘name’: ‘Color’, ‘option’: ‘EC BLK CLSSC STR’}]}

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @ritaalamino

    We added gallery response with REST API, when you retrieve variation product via REST API.

    GET /wp-json/wc/v3/products/PRODUCT_ID/variations/VARIATION_ID

    you will see that there is also woo_variation_gallery_images response available.

    But seems you want to add image via API to the gallery. It’s also possible, Let me explain how.

    Open this file: /wp-content/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-product-variations-controller.php

    there is a function named prepare_object_for_database where woocommerce_rest_pre_insert_product_variation_object filter is available to receive your request. Now check how variation images are inserted. You will get an idea.

    Remember that after processing your request you have to add image ids on woo_variation_gallery_images product meta.

    Thank you

    Thread Starter Rita Alamino

    (@ritaalamino)

    I’ve added this

    
    apply_filters( ‘woocommerce_rest_pre_insert_product_variation_object’, $request ) ;
    

    inside the function prepare_object_for_database

    but I can not understand the resulting JSON. How Am I gonna be able to get the ID? Should I generate the ID? The function responded with an extra field at the JSON string, but it does not have ID at the images.

    "image":[
          {
             "src":"https://url.jpg"
          },
          {
             "src":" https://url.jpg"
          },
          {
             "src":" https://url.jpg"
          },
          {
             "src":" https://url.jpg"
          },
          {
             "src":" https://url.jpg"
          }
       ],
       "attributes":[
          {
             "id":4,
             "name":"Size",
             "option":"XS"
          },
          {
             "id":3,
             "name":"Color",
             "option":"CAMO"
          }
       ]
    • This reply was modified 3 years, 6 months ago by Rita Alamino.
    • This reply was modified 3 years, 6 months ago by Rita Alamino.
    • This reply was modified 3 years, 6 months ago by Rita Alamino.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add images variation via Rest API’ is closed to new replies.