Skip to content

rwestlund/quickbooks-go

Repository files navigation

quickbooks-go

Build GoDoc Go Report Card

quickbooks-go is a Go library that provides access to Intuit's QuickBooks Online API.

NOTE: This library is incomplete. I implemented the minimum for my use case. Pull requests welcome :)

Example

Authorization flow

Before you can initialize the client, you'll need to obtain an authorization code. You can see an example of this from QuickBooks' OAuth Playground.

See auth_flow_test.go

clientId     := "<your-client-id>"
clientSecret := "<your-client-secret>"
realmId      := "<realm-id>"

qbClient, err := quickbooks.NewClient(clientId, clientSecret, realmId, false, "", nil)
if err != nil {
	log.Fatalln(err)
}

// To do first when you receive the authorization code from quickbooks callback
authorizationCode := "<received-from-callback>"
redirectURI := "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl"

bearerToken, err := qbClient.RetrieveBearerToken(authorizationCode, redirectURI)
if err != nil {
	log.Fatalln(err)
}
// Save the bearer token inside a db

// When the token expire, you can use the following function
bearerToken, err = qbClient.RefreshToken(bearerToken.RefreshToken)
if err != nil {
	log.Fatalln(err)
}

// Make a request!
info, err := qbClient.FindCompanyInfo()
if err != nil {
	log.Fatalln(err)
}

fmt.Println(info)

// Revoke the token, this should be done only if a user unsubscribe from your app
qbClient.RevokeToken(bearerToken.RefreshToken)

Re-using tokens

See reuse_token_test.go

clientId     := "<your-client-id>"
clientSecret := "<your-client-secret>"
realmId      := "<realm-id>"

token := quickbooks.BearerToken{
	RefreshToken:           "<saved-refresh-token>",
	AccessToken:            "<saved-access-token>",
}

qbClient, err := quickbooks.NewClient(clientId, clientSecret, realmId, false, "", &token)
if err != nil {
	log.Fatalln(err)
}

// Make a request!
info, err := qbClient.FindCompanyInfo()
if err != nil {
	log.Fatalln(err)
}

fmt.Println(info)

License

BSD-2-Clause

About

A Go library for Intuit's QuickBooks Online API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages