Ionic with woocommerce Rest API


I develop a new Project using Wordpress Rest API.

I refer this

I installed

  npm install oauth-1.0a --production

  npm install crypto-js

Here is my code

 import OAuth from 'oauth-1.0a'
import CryptoJS from 'crypto-js';

export class ApiProvider {
  oauth: any;
  constructor(public http: Http,public Events:Events,public storage: Storage) {
    console.log('Hello ApiProvider Provider');
      baseurl: '',
      apiUrl: '',
      consumerkey: 'ck_2b9a76417280178b642975df59aaaf9ebf816247',
      consumersecret: 'cs_a0b51e4ced110bc08180824bcdee6dc1bf498341'


 //Get Categories

    function hash_function_sha1(base_string, key) {
        return CryptoJS.HmacSHA1(base_string, key).toString(CryptoJS.enc.Base64); 
        //return crypto.createHmac('sha1', key).update(base_string).digest('base64');
    this.oauth = new OAuth({
        consumer: {
            key: this.apiconstant.consumerkey,
            secret: this.apiconstant.consumersecret
        hash_function: hash_function_sha1,
        signature_method: 'HMAC-SHA1'

    var request_data = {
        url: this.apiconstant.apiUrl+'products/categories',
        method: 'GET'

    this.authkey = this.oauth.authorize(request_data);
    this.keyoauth = new URLSearchParams();
    for(let param in this.authkey) {
        this.keyoauth.set(param, this.authkey[param]);
    let options = new RequestOptions({
        method: request_data.method,
        url: request_data.url,
       headers: this.oauth.toHeader(this.oauth.authorize(request_data)),
       search: this.keyoauth

    return this.http.get(this.apiconstant.apiUrl+'products/categories',options)
    .map(res => res.json());

Here is my output

OPTIONS…=1501734186&oauth_version=1.0&oauth_signature=wsM+lvma2154IOlEWbhgGQJNcv0= 401 (Unauthorized)

But the same URL copy and ran the browser I got Output.

How can i fix this issue.

Kindly advice me,


Your app makes an OPTIONS request. Your browser probably did a GET request. These are different. This is all because of CORS and browser security, no real workaround.

If you are testing in browser, you might be able to use a Service Proxy in the CLI to work around it though:

Thanks for ur reply.why I am getting Unauthorized error.

Because your server probably doesn’t handle the OPTIONS request the correct way.


This API only work Browser.Does not support mobile.

I got 404 found error message.Same time I copied URL and ran browser i got output.

How can i fix this issue.

Is a server problem or coding problem ?

I dont understand.

Kindly advice me,