woocommerce / wc-api-ruby

A Ruby wrapper for the WooCommerce API.
MIT License
69 stars 74 forks source link

how to make update requests #45

Closed carloslima18 closed 5 years ago

carloslima18 commented 5 years ago
store = OpenStruct.new(woocommerce_url: "https://alforriamoveis.com.br//wp-json/wc/v3/products/13409", token: "ck_6203256344errhello44", consumer_secret: "cs_d0203256344errhello44")
@prod = WooCommerce::API.new(
    store.woocommerce_url,
    store.token,
    store.consumer_secret,
      {
        wp_api: true,
        version: "wc/v3"
      }
    )

prod.post("//wp-json/wc/v3/products/13409", '{"name": "hello"}')

but this not worked

error code: rest_no_route

carloslima18 commented 5 years ago

find how work..

substituinfo por...

store = OpenStruct.new(woocommerce_url: "https://alforriamoveis.com.br//wp-json/wc/v3/products/13409?", token:

...

....

response2 = @prod.put('/', {"name": "hello"})

....

claudiosanches commented 5 years ago

You should use:

store = OpenStruct.new(woocommerce_url: "https://alforriamoveis.com.br/", token: "ck_6203256344errhello44", consumer_secret: "cs_d0203256344errhello44")
@prod = WooCommerce::API.new(
    store.woocommerce_url,
    store.token,
    store.consumer_secret,
      {
        wp_api: true,
        version: "wc/v3"
      }
    )

Since this library will compose this peace wp-json/wc/v3/, and then you should use @prod.get("products/13409"). Also not that there's no parameter name like in your example '{"name": "hello"}.

You can find more example in the REST API documentation, there's complete examples for this library: https://woocommerce.github.io/woocommerce-rest-api-docs/?ruby#introduction