0
votes

I've been trying to connect to the REST API of Woocommerce (using HTTP Basic Auth) but fail to do so.

I'm probably doing stuff wrong (first timer @ REST API's), but here is what I've been doing:

  • I'm using a GET with an url consisting of: https://example.com/wc-api/v2/
  • I'm using an Authorization header with the consumer key and secret base64 encoded

I've enabled the REST Api in the Woocommerce setting and enabled secure checkout. Also I've put some product in the shop. But whenever I try to run the URL as described above; the connection is just being refused.

I do not receive an error, but it looks like the page cannot even be reached. Can someone help me out?

I've followed the docs (http://woothemes.github.io/woocommerce-rest-api-docs/#requestsresponses) up to the Authentication-section, but that's where I've been stuck up till now. The complete url I'm using is:

http://[MYDOMAIN]/wc-api/v2/orders

With the HTTP-header looking like:

GET /wc-api/v2/ HTTP/1.1 Authorization: Basic [BASE64 encoded_key:BASE64 encoded_secret] Host: [MYDOMAIN] Connection: close User-Agent: Paw/2.1.1 (Macintosh; OS X/10.10.2) GCDHTTPRequest

Then after I run the request I'm getting:

after following the url

2
You don't receive any error at all? Not even a 404 or 403? What happens if you try connecting to the same URL with cURL or something like that? - Dan Blows
Nope, not seeing anything. I'm using the PAW REST client for Mac (just as a convenience) - Gee.E
So you're just trying to get a list of orders and the request is timing out? Is there anything in your logs - either PHP or Apache/nginx? At least, is nginx/Apache receiving the request and handling it correctly? If it's handing to the correct script, then try installing xdebug and watch where the process is hanging. At a guess, it could be making an external request which itself is taking a long time to respond. - Dan Blows
Where do I find the logs? The logs at WooCommerce > System status > Logs show an empty log file. My main objective is to connect with WooCommerce from within an iOS app, to get a list of products. From what I understand; I can do some request using the WooCommerce's REST API (like getting the products), and receive them in JSON format. - Gee.E
You want your webserver's logs - if your webserver is on Linux, usually you'll find them in /var/logs/nginx or /var/logs/apache. Are you connecting over localhost, or from one server to another? If not, perhaps you're being blocked by a firewall. - Dan Blows

2 Answers

1
votes

Given the screenshot that you posted, it seems that the server is not responding on HTTPS. So you'll need to configure your webserver to respond to HTTPS requests, and to do that you'll need to install an SSL certificate.

You can either generate one yourself, which is free, but won't work for the general public. Or you can buy one - most domain registrars and hosts will let you buy a certificate, and they usually start at around $50 per year.

0
votes

I'm using a GET with an url consisting of: https://example.com/wc-api/v2/

In this example, you're using HTTPS. Is that where you're trying to connect?

I highly recommend going straight to HTTPS connection. It's a thousand times easier to accomplish. Documentation for over HTTPS can be found here. Follow directions for "OVER HTTPS". From there you can use something like Postman to test if you'd like.