This module implements a Go REST client for the public API from lexoffice. With the help of the API one can work with entities from the cloud-based accounting software.
To work with the lexoffice API, you need to setup a lexoffice test instance and get an API key.
Thankfully these steps can be done online (without credit card) in some minutes.
To get the test instance (provided 30 days free of charge by lexoffice), just hit https://www.lexoffice.de and create your test-account. You have to verify your email address and setup your password on first login.
After you have successfully logged in, just go to https://app.lexoffice.de/settings/#/public-api to create your API key, attached to your instance and valid for 24 months.
You can find the vendor explanation for this in the cookbook.
This module needs this API key to connect. You'll provide the API key as an environment variable or in an .env file (you can also hard-code it in your project if you dare).
To export the API key in an environment variable, just define it, e.g.
~ export LEXOFFICE_API_KEY=########-####-####-####-############
Alternatively, To create the .env file, just run:
~ echo "LEXOFFICE_API_KEY=########-####-####-####-############" > .env
You can check the file content with:
~ cat .env
LEXOFFICE_API_KEY=########-####-####-####-############
Of course you can provide the API key in every command, also, eg.:
LEXOFFICE_API_KEY=########-####-####-####-############ go test -v -tags=integration
go get -u github.com/wolfgang-werner/lexoffice-go-api
import "github.com/wolfgang-werner/lexoffice-go-api"
// Replace API_KEY with your real key
client := lexoffice.NewClient("API_KEY")
// enable debug output
client.debug = true
Run integration tests with real API Key.
LEXOFFICE_API_KEY=########-####-####-####-############ go test -v -tags=integration
The following resources have been very helpful in writing this module.
-
lexoffice API Documentation and Getting Started
-
Helpful advice from Alex Pliutau - thank you Alex! - good read Writing REST API Client in Go
and the corresponding GitHub repository facest / factest-go -
JSON-to-Go, a cool online tool to convert JSON to Go type definition
-
Some in-deep knowledge - how to deal with dynamic JSON structures in Go.
Good starting points are Go JSON Cookbook and Representing JSON structures in Go, both from Eli Bendersky and Dynamic JSON in Go from Tommi Virtanen