WooCommerce API - Ruby Client

A Ruby wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library.

Installation

gem install woocommerce_api

Getting started

Generate API credentials (Consumer Key & Consumer Secret) following this instructions docs.woocommerce.com/document/woocommerce-rest-api/ .

Check out the WooCommerce API endpoints and data that can be manipulated in woocommerce.github.io/woocommerce-rest-api-docs/.

Setup

Setup for the new WP REST API integration (WooCommerce 2.6 or later):

require "woocommerce_api"

woocommerce = WooCommerce::API.new(
  "http://example.com",
  "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  {
    wp_api: true,
    version: "wc/v1"
  }
)

Setup for the WooCommerce legacy API:

require "woocommerce_api"

woocommerce = WooCommerce::API.new(
  "http://example.com",
  "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  {
    version: "v3"
  }
)

Options

| Option | Type | Required | Description | | —————– | ——– | ——– | —————————————- | | url | String | yes | Your Store URL, example: woo.dev/ | | consumer_key | String | yes | Your API consumer key | | consumer_secret | String | yes | Your API consumer secret | | args | Hash | no | Extra arguments (see Args options table) |

Args options

Option Type Required Description
`wp_api` `Bool` no Allow requests to the WP REST API (WooCommerce 2.6 or later)
`version` `String` no API version, default is `v3`
`verify_ssl` `Bool` no Verify SSL when connect, use this option as `false` when need to test with self-signed certificates
`signature_method` `String` no Signature method used for oAuth requests, works with `HMAC-SHA1` and `HMAC-SHA256`, default is `HMAC-SHA256`
`query_string_auth` `Bool` no Force Basic Authentication as query string when `true` and using under HTTPS, default is `false`
`debug_mode` `Bool` no Enables HTTParty debug mode
`httparty_args` `Hash` no Allows extra HTTParty args

Methods

| Params | Type | Description | | ———- | ——– | ———————————————————— | | endpoint | String | WooCommerce API endpoint, example: customers or order/12 | | data | Hash | Only for POST and PUT, data that will be converted to JSON | | query | Hash | Only for GET and DELETE, request query string |

GET

POST

PUT

DELETE

OPTIONS

Response

All methods will return HTTParty::Response object.

response = api.get "customers"

puts response.parsed_response # A Hash of the parsed JSON response
# Example: {"customers"=>[{"id"=>8, "created_at"=>"2015-05-06T17:43:51Z", "email"=>

puts response.code # A Interger of the HTTP code response
# Example: 200

puts response.headers["x-wc-total"] # Total of items
# Example: 2

puts response.headers["x-wc-totalpages"] # Total of pages
# Example: 1

Release History