A Woocommerce API Golang Wrapper for the Woocommerce Rest API (v3)
$ go get github.com/dinistavares/go-woocommerce-api
Create a new API client and authenticate with your REST API keys. You should specify the URL protocol by prefixing your domain name with https://
or http://
. Follow the Woocommerce documentation to create your API keys through the Wordpress admin interface or using the authentication endpoint.
import (
"github.com/dinistavares/go-woocommerce-api"
)
func main(){
shopURL := "https://example.com"
key := "ck_xxxxxxx"
secret := "cs_xxxxxxx"
client, err := woocommerce.New(shopURL)
if err != nil {
// handle error
return
}
client.Authenticate(key, secret)
}
The API routes are broken down into services, the supported services are:
- Coupons
(Create, Get, List, Update, Delete, Batch)
- Customers
(Create, Get, List, Update, Delete, Batch, GetDownloads)
- Orders
(Create, Get, List, Update, Delete, Batch)
- OrderNotes
(Create, Get, List, Delete)
- Refunds
(Create, Get, List, Delete)
- Products
(Create, Get, List, Update, Delete, Batch)
- Webhooks
(Create, Get, List, Update, Delete, Batch)
List Orders by customer ID and page number.
func (client *woocommerce.Client) listOrders() {
customerID := 3
pageNumber := 1
opts := woocommerce.ListOrdersParams{
Customer: customerID,
Page: pageNumber,
}
orders, resp, err := client.Orders.List(opts)
if err != nil {
// Handle errors
return
}
// Pagination headers.
totalPages := resp.Header.Get("X-Wp-Totalpages")
totalItems := resp.Header.Get("X-Wp-Total")
// ....
}