datascientist110
datascientist110

Reputation: 75

How to generate API endpoints for my Products from Wordpress using Woocommerce REST API?

I have created a Shopping Cart Website with Wordpress and Woocommerce Plugin. Now I want to access these products from my Ionic App.

Now, whenever I try to access these endpoints using Woo REST API. It gives the following Errors.

http://localhost:8888/myshop/wp-json/wc/v3/products/
{
     code: "rest_no_route",
     message: "No route was found matching the URL and request method",
     data: {
            status: 404
           }
}

Upvotes: 1

Views: 2217

Answers (3)

Harindu Lakshan
Harindu Lakshan

Reputation: 25

http://localhost:8888/wp-json/wc/store/products

Try this endpoint for list products

Upvotes: 1

mujuonly
mujuonly

Reputation: 11861

Please check and verify WooCommerce REST API option is added under, www.mydomain.com/wp-admin/admin.php?page=wc-settings&tab=advanced&section=keys

For making custom API end points, this snippet can be used.

add_action('rest_api_init', 'init_my_rest_api');


function init_my_rest_api() {
        register_rest_route('myaction/v1', '/getdetails/', array(
            'methods' => 'POST',
            'callback' => 'gather_details',
        ));
    }

Upvotes: 1

Vnfaster.com
Vnfaster.com

Reputation: 46

My Solution,

Step 1: Create a page:

<?php
/*
 Template Name: Products API
*/
$productlist = array();
$vnfaster = new WP_Query(array(
'post_type'=>'product',
'post_status'=>'publish',
'orderby' => 'ID',
'order' => 'DESC',
));
while ($vnfaster->have_posts()) : $vnfaster->the_post();
$productlist[] = array( 'id' => $post->ID, 'title' => $post->post_title );
endwhile ; wp_reset_query();
echo json_encode( $productlist );
?>

Step 2: I have a Page: http://localhost:8888/myshop/products-api

Output:

{
     id: "1",
     title: "Product 1",
    ...
}

Upvotes: 0

Related Questions