• Resolved wordpressmenow

    (@wordpressmenow)


    hello

    first, great plugin – thanks!

    user with the following roles:
    read
    read products
    Manage product terms
    Read private products
    list users

    gives the following error in REST api v3 (legacy):
    “woocommerce_api_user_cannot_read_product_categories”

    it happens only with categories…

    any idea?

    thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    Thanks for feedback.
    This exception ‘woocommerce_api_user_cannot_read_product_categories’ is used by WooCommerce 2 times, file class-wc-api-products.php, lines #614, #652.
    In both cases code checks ‘manage_product_terms’ capability:

    
    if ( ! current_user_can( 'manage_product_terms' ) ) {
       throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_product_categories', __( 'You do not have permission to read product categories', 'woocommerce' ), 401 );
    

    Recheck if current user at your test really has ‘manage_product_terms’ capability.

    Plugin Author Vladimir Garagulya

    (@shinephp)

    It made my own test using this library.
    User has this capabilities:
    manage_product_terms
    read
    read_private_products
    read_product

    I sent this request using keys generated for user above:

    
    $woocommerce = new Client(
        'http://test.my/wp-test2', 
        'ck_xxxx', 
        'cs_xxxx',
        [
            'wp_api' => false,
            'version' => 'v3',
        ]
    );
    $endpoint = 'products/categories';
    $parameters = array();
    $data = $woocommerce->get($endpoint, $parameters);
    var_dump($data);
    

    and got the expected response:

    
    array (size=1)
      'product_categories' => 
        array (size=3)
          0 => 
            array (size=8)
              'id' => int 46
              'name' => string 'Cat1' (length=4)
              'slug' => string 'cat1' (length=4)
              'parent' => int 0
              'description' => string '' (length=0)
              'display' => string 'default' (length=7)
              'image' => string '' (length=0)
              'count' => int 0
          1 => 
            array (size=8)
              'id' => int 47
              'name' => string 'Cat2' (length=4)
              'slug' => string 'cat2' (length=4)
              'parent' => int 0
              'description' => string '' (length=0)
              'display' => string 'default' (length=7)
              'image' => string '' (length=0)
              'count' => int 0
          2 => 
            array (size=8)
              'id' => int 48
              'name' => string 'Cat3' (length=4)
              'slug' => string 'cat3' (length=4)
              'parent' => int 0
              'description' => string '' (length=0)
              'display' => string 'default' (length=7)
              'image' => string '' (length=0)
              'count' => int 0
    

    So re-check if you use valid oAuth keys also.

    Thread Starter wordpressmenow

    (@wordpressmenow)

    Hello Vladimir

    thank you for your professional support 🙂

    actually, problem was solved just by last update – once I updated both woocommerce and User Role Editor… (not URE alone).

    AAA+++ for this amazing plugin and support!

    again, thank you 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘woo REST API legacy v3 error’ is closed to new replies.