Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @shashinasiri,

    Great question. You can get products via version 3 of the REST API with their SKU. If the SKU is 5346 then the request would look like this:

    
    https://site.com/wp-json/wc/v3/products/?sku=5346
    

    When using a POST to create a product, you don’t have to send the SKU in the URL. That can be part of the body of the request. If you need to update an existing product, that will use the ID. You may need to use the SKU to grab the ID and then update with it.

    Here’s the URL to the documentation on the REST API so you can see examples of how this is designed to work.

    https://woocommerce.github.io/woocommerce-rest-api-docs

    Let us know if you have any questions.

    Thread Starter shashinasiri

    (@shashinasiri)

    Thanks for your reply.

    Can I get an example to the second part of your answer

    You may need to use the SKU to grab the ID and then update with it.

    Sure thing. This will be a two-step process. You would need to grab the product via the SKU.

    https://site.com/wp-json/wc/v3/products/?sku=5346

    Once you have that, the response will then have the product ID in it. Here’s part of an example from the docs:

    
    [
      {
        "id": 799,
        "name": "Ship Your Idea",
        "slug": "ship-your-idea-22",
        ...
    

    You can then make a new request using the correct product ID. That could be like this:

    https://site.com/wp-json/wc/v3/products/584

    where 584 is the ID of the product that was just retrieved. You can use a PUT request to update an existing product.

    Let me know if you have any other questions.

    Hi @shashinasiri,

    Hopefully, you were able to clear up this issue. Since it’s been a while since we last heard from you, I’m going to mark this thread resolved.

    If you still have trouble, please feel free to open up a new topic. We’d be happy to jump back in and help you out.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to update/modify products from API with SKU as the identifier’ is closed to new replies.