• Resolved pioneerweb

    (@pioneerweb)


    I’m trying to create a product with multiple high res images but I’m encountering a lot of issues. First I tried to just add all the images at the same time in the proper format but the Woocommerce httpClient kept timing out. Even after I added ‘timeout’ => 0 when i create the client, it was getting through around 3 images then just throwing a json syntax error or something (format/syntax is fine I’ve triple checked with the docs).

    Adding links individually works (so all the links are fine) but how can I add images to the product gallery one at a time so it doesn’t complain? I’ve tried something like this:

    $data['images'][0] = $images[0];
    $wc->post('products',$data)
    for($i = 1; $i < count($images); $i++)
       $wc->put('products/'.$id, [
                  'images' => [
                               $i => $images[$i]
                              ]
                  ]);
    

    But it just replaces the one image each put and I’m left with the last image in the array.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    Custom code is out of the scope of this forum. Since this is a development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    We recommend reaching out to:

    * The WooCommerce Developer Resources Portal
    * WooCommerce Facebook group
    * The #developers channel of the WooCommerce Community Slack.

    Thank you.

    Thread Starter pioneerweb

    (@pioneerweb)

    Well it’s more about the functionality of the woocommerce PUT function, since it seems to always overwrite images rather than add to the existing gallery. The “custom code” was just for context.

    The problem is I don’t have the option of uploading all the images at once with POST, so how can I do it one at a time with PUT?

    Hi @pioneerweb

    Thanks for your response.

    I don’t have the option of uploading all the images at once with POST, so how can I do it one at a time with PUT?

    As this is a development oriented question, we recommend reaching out to the other channels suggested above.

    Kindly note that this particular forum is for questions that are related to the WooCommerce core features. You can consult the Support Policy here: https://woocommerce.com/support-policy/.

    Hopefully, you will find a way forward with the issue soon. If you do not get inputs here, you can also opt for direct assistance with code customizations through the WooCommerce Customizations Partners at https://woocommerce.com/customizations/, apart from the channels listed above.

    Nevertheless, this thread open for any developer to chime in to help you out here.

    Cheers

    Thread Starter pioneerweb

    (@pioneerweb)

    I’ve found a temporary solution:

    • 1. Download images with a different httpclient like guzzle to local cache
    • 2. Upload images one at a time with curl straight to wordpress library, getting the IDs as you go
    • 3. Include only the image IDs in the POST() with the API
    • This is a great example of how to do the above.

      This also proves that curl is up to the task just fine while the POST command just complains about lots of images even though it’s using curl. Still takes about 3 minutes to create one product though…

    Awesome! Thanks for sharing this with the WooCommerce community.

    It’ll be helpful for others who have a similar requirement.

    Thanks

    We’ve not seen any activity on this thread for a while, so I’m going to mark the thread closed.

    Please feel free to open a new topic if you have any other questions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding images with REST API’ is closed to new replies.