Home:ALL Converter>Unable to connect woocommerce rest api with angular 4

Unable to connect woocommerce rest api with angular 4

Ask Time:2018-02-09T12:38:26         Author:Santosh Vishwakarma

Json Formatter

I am trying to connect my woocommerce rest api with angular 4 to fetch product list in my ionic 3 project but every time url throw 404 not found errror i am not able to understand what i am doing wrong

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import * as WC from 'woocommerce-api';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  WooCommerce: any;

  constructor(public navCtrl: NavController) {

    this.WooCommerce = WC({
      url: "http://localhost:8100/wordpress/wp-json/",
      consumerKey: "ck_4d99b09e85e45a11282fe2150945fc2090eea0f0",
      consumerSecret: "cs_3acf2c3eeb334ab84309e890a5070f8509de9201"
    });

    this.WooCommerce.getAsync("products").then( (data) => {
      console.log(data);
    }, (err) => {
      console.log(err);
    });

  }

}

Author:Santosh Vishwakarma,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/48698813/unable-to-connect-woocommerce-rest-api-with-angular-4
Mahesh Jadhav :

First thing Santosh you should always avoid using your private keys while asking questions , just mention like i did.\n\ni am using this api currently in my app and faced the same issue, try using the exact same url which you use to open the site locally.\ni think changing your url to just \"http://localhost:8100/wordpress/\" should work\n\nthis.WooCommerce = WC({\n url: \"http://localhost:8100/wordpress/\",\n consumerKey: \"your consumer key\",\n consumerSecret: \"your consumer secret\"\n});\n\n\nor else in my case i just passed version along it and it worked, you can check by passing both wpApi and version and hopefully that works\n\nthis.WooCommerce = WC({\n url: \"http://localhost:8100/wordpress/\",\n consumerKey: \"your consumer key\",\n consumerSecret: \"your consumer secret\",\n wpAPI: true,\n version: 'v3'\n});\n",
2018-02-09T05:48:50
yy