- Notifications
You must be signed in to change notification settings - Fork3
A Golang wrapper for the WooCommerce API.
License
darh/wc-api-golang
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Golang wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library.This is a fork ofmikespook/wc-api-golang
. Main difference: get/post/put/delete accepts context and package useshttp.DefaultClient
andhttp.DefaultTransport
.
This lib isnot backward compatible with mikespook/wc-api-golang`!
$ go get github.com/darh/wc-api-golang/woocommerce
Generate API credentials (Consumer Key & Consumer Secret) following this instructionshttp://docs.woocommerce.com/document/woocommerce-rest-api/.
Check out the WooCommerce API endpoints and data that can be manipulated inhttps://woocommerce.github.io/woocommerce-rest-api-docs/.
Setup for the new WP REST API integration (WooCommerce 2.6 or later):
import ( wc"github.com/darh/wc-api-golang/woocommerce")varwoocommerce=wc.NewClient("http://example.com","ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",&wc.Options {API:true,Version:"wc/v1", },);
Option | Type | Description |
---|---|---|
store | string | Your Store URL, example:http://woo.dev/ |
ck | string | Your API consumer key |
cs | string | Your API consumer secret |
options | *wc.Options | Extra arguments (see client options table) |
Option | Type | Description |
---|---|---|
API | bool | Allow make requests to the new WP REST API integration (WooCommerce 2.6 or later) |
APIPrefix | string | Custom WP REST API URL prefix, used to support custom prefixes created with therest_url_prefix filter |
Version | string | API version, default isv3 |
Timeout | time.Duration | Request timeout, default is15 |
VerifySSL | bool | Verify SSL when connect, use this option asfalse when need to test with self-signed certificates, default istrue |
QueryStringAuth | bool | Force Basic Authentication as query string whentrue and using under HTTPS, default isfalse |
OauthTimestamp | time.Time | Custom oAuth timestamp, default istime.Now() |
Params | Type | Description |
---|---|---|
endpoint | string | WooCommerce API endpoint, example:customers ororder/12 |
data | interface{} | Only for POST and PUT, data that will be converted to JSON |
parameters | url.Values | Only for GET and DELETE, request query string |
rc,err:=woocommerce.Get(ctx,endpoint,parameters)
rc,err:=woocommerce.Post(ctx,endpoint,data)
rc,err:=woocommerce.Put(ctx,endpoint,data)
rc,err:=woocommerce.Delete(ctx,endpoint,parameters)
rc,err:=woocommerce.Options(ctx,endpoint)
All methods will return aio.ReadCloser
andnil
on success or anerror
on failure.