• Resolved simlock

    (@simlock)


    Hello,

    I have a problem with the API not wanting to respond to a specific request. I get this error message in response:

    Object {
      "code": "woocommerce_rest_cannot_view",
      "data": Object {
        "status": 401,
      },
      "message": "Sorry, you cannot list resources.",
    }

    My request to retrieve all my products works but as soon as I want to make a request to return a product with a specific SKU, it displays me the error message…
    What I don’t understand is that with the same parameters in Python, it works fine but on my application in Javascript it rejects me.

    const WooCommerce = new WooCommerceAPI({
        url: 'https://myURL.com',
        consumerKey: 'xxxxxxxxxxxxxxxxxxxx',
        consumerSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
        version: 'wc/v3',
        queryStringAuth: true
      });

    Work (javascript):
    WooCommerce.get('products')

    Don’t Work (javascript):
    WooCommerce.get('products?sku=MK_MB"')

    Work (python):
    wcapi.get("products?sku=MK_MB").json()

    Do you know why I can’t make the request work in Javascript?

    Thank you for your help !

Viewing 1 replies (of 1 total)
  • Thread Starter simlock

    (@simlock)

    So, finally, my request works if it is written this way…

    WooCommerce.get('products', { 'sku': 'MK_MB' })

Viewing 1 replies (of 1 total)
  • The topic ‘JS API “code”: “woocommerce_rest_cannot_view”’ is closed to new replies.