A Go library is provided to ease the development of Go applications that connect to Ticketmatic. This library is automatically kept in sync with the backend implementation: all endpoints that can be used through the REST API will also be usable through the Go library.

The Go library frees you from the burden of having to implement correct authentication crypto or some of the more tricky type handling: the library takes care of all those things.

Some important features of the Go library:

  • Converts all results into typed objects
  • All documentation is included inline, for use with GoDoc. A link to the knowledge base is also included, allowing you to jump back and forward quickly.
  • Automatically handles conversions between the Ticketmatic time format and Go’s builtin time.Time type.
  • Supports custom fields

Getting the library

The Go library is available on Github: https://github.com/ticketmatic/tm-go.

It can be easily fetched through go get:

go get github.com/ticketmatic/tm-go

There is also an RSS (Atom) feed available at https://github.com/ticketmatic/tm-go/releases.atom if you want to be notified on new releases.

Library structure

Most types are available in the ticketmatic package (github.com/ticketmatic/tm-go/ticketmatic).

Endpoint operations are structured in subpackages in the same way as the REST API is structured.

Creating an API client

All operations require a Client object:

1import "github.com/ticketmatic/tm-go/ticketmatic"
3client := ticketmatic.NewClient(accountcode, accesskey, secretkey)

You can find the account code and access keys on the details page of your application. See Authentication for more details on how to obtain API keys.

This client object should be passed as the first parameter to all operations. For instance, to fetch a contact you’d do the following:

1import "github.com/ticketmatic/tm-go/ticketmatic/contacts"
3// Fetch the contact with ID 123
4contact, err := contacts.Get(client, 123, nil)
5if err != nil {
6    // Handle error

Custom fields

Custom fields are added as extra fields to objects in the REST API. We can’t do this in the Go library: the format of structs need to be decided in advance.

To work around this limitation, custom fields are automatically mapped into a CustomFields field on types that support custom fields. The type of this field is map[string]interface{}. It is up to you to correctly handle the data in these fields.

See custom fields for an example.