WooCommerce API NPM implementation


#1

How can i implement this woocomerce rest api to ionic 2?

I tried to import it but it’s not working

https://www.npmjs.com/package/woocommerce-api


#2

Can you share what you’ve tried? Can’t really help out too much if we don’t know what you’ve tried to do?


#3

@mhartington I installed , below are the screenshots my implementation.

https://www.npmjs.com/package/woocommerce-api





#4

The npm package you posted isn’t meant to be used in the browser.
It’s a node package that’s meant to be used on a node-server.
Not loaded in the browser


#5

Thank you. I will try to find other solution.


#6

Did you find any solution on implementing Woocommerce on Ionic2 App? I’m trying to do the same thing…


#7

You can try this one, this works for me.

https://www.npmjs.com/package/oauth-1.0a

add in the index.html

      <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>
<!-- sha256 -->
   <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha256.js"></script>
   <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js">        </script>
<script src="oauth-1.0a.js"></script>


   var oauth = new OAuth({
        consumer: {
            public: 'ck_ public key here',
            secret: 'cs_ secret key here'
        },
        signature_method: 'HMAC-SHA1'
    });

Just follow the guidelines below:
http://woothemes.github.io/woocommerce-rest-api-docs/#authentication



#8

First thank you for your answer! Nice community over there…

Please would you be so kind as to show me the full process?

  • I added the scripts you provided me to index.html with my ck_ & cs_(triple check they’re matching)

  • Then change my url to http://urlBase/projet_mobile/wc-api/v3/products in my wordpress.service.ts

  • Then return this._http.get(url).map(res => res.json());

  • Then on my wordpress.ts : ngOnInit() {
    this._wordpressService.getProducts()
    .subscribe(
    response => this.response = response,
    error => console.log(error));
    }

And finally {{response | json}} to see content.

In the console log I have the following error:

XMLHttpRequest cannot load http://url/projet_mobile/wc-api/v3/products. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access. The response had HTTP status code 404

Would be awesome to get this thing working, as I’ve been fighting with this for over 3weeks…
Sorry for my noobness(and my poor english), I just started coding…

My best regards,
Yin.


#9

@yin67

you may try either add this in your wordpress functions.php

    add_action( 'init', 'allow_origin' );
       function allow_origin() {
        /* or you can specify the origin e.q http://localhost */
         header("Access-Control-Allow-Origin: *");
     }

or

   <meta http-equiv="Content-Security-Policy" content="script-src * 'unsafe-inline' 'unsafe-eval'">

#10

Ok thanks I added it to the header of the woocommerce theme functions.php theme.

But now I have a problem with the oauth_consumer_key missing:

Response {_body: "{"errors":[{"code":"woocommerce_api_authentication…aram\u00e8tre oauth_consumer_key est manquant"}]}", status: 404, statusText: "Ok", headers: Headers, type: 2…}
_body
:
"{"errors":[{"code":"woocommerce_api_authentication_error","message":"Le param\u00e8tre oauth_consumer_key est manquant"}]}"

Can you show me how you built your oauth Authentication? Thank you very much, really appreciate the help.


#11

Hello guys can you please add more details on how to implement this solution i have the same issue and i couldnt’t make this work and running out of options


#12

change your import ‘woocommerce-api’ to import { WooCommerceAPI } from ‘woocommerce-api’;


#13

Hi everyone.
Did Someone could integrate woocommerce REST api module at ionic 2 framework?
i’ll been grateful for some help.
Thanks!


#15

Hi @JosephMendez where I have to define the WooCommerce implementation block?


#17

please any one can help me for similar problem here ?