Skip to content

Instantly share code, notes, and snippets.

@jpillora jpillora/xero-api.go
Created Apr 27, 2016

What would you like to do?
Xero API for Private applications in Go (golang)
package main
import (
const (
XeroRequestTokenURL = ""
XeroAuthorizeTokenURL = ""
XeroAccessTokenURL = ""
XeroApiEndpointURL = ""
func main() {
//parse your private key (see
path := "/path/to/my/xero-private.pem"
pemBytes, err := ioutil.ReadFile(path)
if err != nil {
block, extra := pem.Decode(pemBytes)
if block == nil || len(extra) > 0 {
log.Fatal("Failed to decode PEM")
privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
//create the oauth1 client using this key (consumer secret not required)
client := oauth.Client{
Credentials: oauth.Credentials{Token: "Z0TXP197I4IEXAMPLE1234"},
TemporaryCredentialRequestURI: XeroRequestTokenURL,
ResourceOwnerAuthorizationURI: XeroAuthorizeTokenURL,
TokenRequestURI: XeroAccessTokenURL,
SignatureMethod: oauth.RSASHA1,
PrivateKey: privateKey,
Header: http.Header{"Accept": []string{"application/json"}}, //noone likes XML
//list all invoices
response, err := client.Get(http.DefaultClient, &client.Credentials, XeroApiEndpointURL+"invoices/", nil)
if err != nil {
defer response.Body.Close()
//show response
contents, err := ioutil.ReadAll(response.Body)
if err != nil {

This comment has been minimized.

Copy link

commented Oct 23, 2018

how do you add query parameters? I get an error when trying to do so, for example: InvoiceReference="xxx"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.