skip to Main Content

I’m trying to get all WooCommerce products list from API to my Vue-script. For common WP API I used code:

fetchPosts: function(){
                  var url = 'https://some-example-website.org/wp-json/wp/v2/post';
                  fetch(url).then((response)=>{
                    return response.json()
                    }).then((data)=>{
                      this.posts = data;                      
                    });
                }, 

and got posts objects array from JSON, and did all I need with it.
I’m trying to use URL https://some-example-website.org//wp-json/wc/v2/products. But it returns 401 error
Is there some simple way just to get products (all data), without any authorization, any secret keys? Or I should be only authenticated user? Can’t find info neither in WC API docs, no another web-resources.

2

Answers


  1. Chosen as BEST ANSWER

    At least (and like some guys advised) I created own "end-point", something like very simple, almost ridiculous API page:

    <?php
    /*
    Template name: Product API Page
    */
    ?>
    
    <?php 
       $query = new WP_Query( 
          array( 'post_type' => 'product', 'posts_per_page' => 0) 
       );
    ?>        
    [    
    <?php
       while( $query->have_posts() ){ $query->the_post();
       global $product;
    ?>   
       {
        "sku":<?php echo $product->get_sku(); ?>,
       "titlte": "<?php the_title(); ?>"
       ... end so on
       },          
    <?php } ?>
    ]
    

    Maybe I was wrong. But it works.


  2. Similar question has been asked, which indicates that none of the WooCommerce REST endpoints are public, but there may be options to do so.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search