exactonline

package module
v0.0.0-...-7cd2dfd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2022 License: MIT Imports: 44 Imported by: 0

README

go-exactonline

GoDoc Build Status Test Coverage Maintainability go report

go-exactonline is a Go client library for accessing the Exact Online API. This library is tested for Go v1.10 and above.

Usage

import "github.com/stack11/go-exactonline"

We first contstruct a client and then access the various API endpoints. Note that this library doens't directly handle authentication, see Authentication.

client := exactonline.NewClient(nil)
ctx := context.Background()

// Get the last used division
divisionID, err := client.GetCurrentDivisionID(ctx)

// Fetch all transactions in the division
transactions, err := client.FinancialTransaction.Transactions.List(ctx, divisionID, false, nil)

Authentication

This library doesn't directly handle authentication. You should provide a http.Client that handles the authentication for you. There are multiple ways to do this, however these are the recommended ways:

tokenSource := oauth2.StaticTokenSource(
    &oauth2.Token{AccessToken: "... your access token ..."},
)
client := exactonline.NewClientFromTokenSource(context.Background(), tokenSource)

Or use your oauth2 configuration and the oauth2 package will automatically refresh the token for you:

token := &oauth2.Token{} // Your previously fetched or stored token

ctx := context.Background()
config := &oauth2.Config{
    RedirectURL:  "the registered redirect URL",
    ClientID:     "the registered client ID",
    ClientSecret: "the registered client secret",
    Endpoint: oauth2.Endpoint{
        AuthURL:  "https://start.exactonline.nl/api/oauth2/auth",
        TokenURL: "https://start.exactonline.nl/api/oauth2/token",
    },
}

tokenSource := config.TokenSource(ctx, token) // this will refresh your access token if a valid refresh token is available
httpClient := oauth2.NewClient(ctx, tokenSource) // Create a http.Client that you want to tweak or use exactonline.NewClientFromTokenSource
client := exactonline.NewClient(nil)

For more examples and information on how to use the oauth2 package, see their documentation.

Divisions

The current division can be fetched using:

divisionID, err := client.GetCurrentDivisionID(context.Background())

Other available divisions can be fecthed through te following enpoints:

// To get all divisions which are accessible for the user that granted the app permission, use:
divisions, err := client.System.Divisions.List(context.Background(), true, nil)
// or if you need to retrieve the divisions for the current license, of the user that granted
// the app permission, use:
divisions, err := client.HRM.Divisions.List(context.Background(), true, nil)

Pagination

By default GET requests are limited to returning 60 records. As a convenience the List method of most endpoints provide a boolean option to fetch all records / pages available.

Permissions

Every endpoint has a method to check if the user has permission for that operation. ie:

ctx := context.Background()
divisionID := 1
method := "GET"

hasListPermission, err := client.FinancialTransaction.Transactions.UserHasRights(ctx, divisionID, method)

Bulk

Some entities support bulk fetching. Bulk fetching will return a maximum of 1000 records per page. These endpoints are located in the Bulk service and return different types than the normal endpoints. This is due too the way this API is generated.

Issues

Issues and/or pull requests are welcome. Note that the services are generated using gen-services.go. If there are issues with the services, take a look at this file or the templates. The service files shouldn't be edites.

Versioning

This library uses symantic versions using git tags. However since this library is still in development, API methods are subject to change.

TODO

  • Add support for non standard endpoints
  • Integration tests
  • Better error handling
  • Web hooks support
  • Documentation and examples

License

This library is distributed under the MIT license found in the LICENSE file.

Documentation

Overview

Package exactonline provides a client for using the Exact Online API.

Usage:

import "github.com/stack11/go-exactonline"

Note that this library doens't directly handle authentication, see [Authentication](#authentication). We first contstruct a client and then access the various API endpoints.

client := exactonline.NewClient(nil)
ctx := context.Background()

// Get the last used division
divisionID, err := client.GetCurrentDivisionID(ctx)

// Fetch all transactions in the division
transactions, err := client.FinancialTransaction.Transactions.List(ctx, divisionID, false, nil)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func Date

func Date(v time.Time) *types.Date

Date is a helper routine that allocates a new types.Date value to store v and returns a pointer to it.

func Float64

func Float64(v float64) *float64

Float64 is a helper routine that allocates a new float64 value to store v and returns a pointer to it.

func GUID

func GUID(v uuid.UUID) *types.GUID

GUID is a helper routine that allocates a new types.GUID value to store v and returns a pointer to it.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func URL

func URL(v *url.URL) *types.URL

URL is a helper routine that allocates a new types.URL value to store v and returns a pointer to it.

Types

type Client

type Client struct {

	// Services used for talking to different parts of the Exact Online API
	Budget               *budget.BudgetService
	Bulk                 *bulk.BulkService
	ContinuousMonitoring *continuousmonitoring.ContinuousMonitoringService
	Documents            *documents.DocumentsService
	FinancialTransaction *financialtransaction.FinancialTransactionService
	General              *general.GeneralService
	Inventory            *inventory.InventoryService
	Accountancy          *accountancy.AccountancyService
	Users                *users.UsersService
	VAT                  *vat.VATService
	Workflow             *workflow.WorkflowService
	PurchaseEntry        *purchaseentry.PurchaseEntryService
	Payroll              *payroll.PayrollService
	Purchase             *purchase.PurchaseService
	SalesOrder           *salesorder.SalesOrderService
	Logistics            *logistics.LogisticsService
	CRM                  *crm.CRMService
	GeneralJournalEntry  *generaljournalentry.GeneralJournalEntryService
	OpeningBalance       *openingbalance.OpeningBalanceService
	Project              *project.ProjectService
	Webhooks             *webhooks.WebhooksService
	Cashflow             *cashflow.CashflowService
	SalesInvoice         *salesinvoice.SalesInvoiceService
	PurchaseOrder        *purchaseorder.PurchaseOrderService
	Sales                *sales.SalesService
	SalesEntry           *salesentry.SalesEntryService
	Mailbox              *mailbox.MailboxService
	Assets               *assets.AssetsService
	Financial            *financial.FinancialService
	HRM                  *hrm.HRMService
	Manufacturing        *manufacturing.ManufacturingService
	Subscription         *subscription.SubscriptionService
	System               *system.SystemService
	Activities           *activities.ActivitiesService
	// contains filtered or unexported fields
}

A Client manages communication with the Exact Online API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Exact Online API client. Provide a http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func NewClientFromTokenSource

func NewClientFromTokenSource(ctx context.Context, tokenSource oauth2.TokenSource) *Client

NewClientFromTokenSource is a wrapper around NewClient if you have a valid token source. It will create a http.Client from the oauth2.Tokensource. If no context is available you can use context.Background()

func (*Client) GetCurrentDivisionID

func (c *Client) GetCurrentDivisionID(ctx context.Context) (int, error)

GetCurrentDivisionID fetches the last used division id of the user. Other divisions available can be fetched through the `Client.System.Divisions` or `Client.HRM.Divisions` endpoints.

func (*Client) GetMe

func (c *Client) GetMe(ctx context.Context) (*system.Me, error)

GetMe returns the current user

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(baseURL string) error

SetBaseURL sets the base URL for communicating with the Exact Online API. If the URL does not have a trailing slash, one is added automatically. For each country, the Exact Online solution is deployed on a separate site. Because of this, the Exact Online server URL is country dependent. The Exact Online server URLs are:

Docs: https://support.exactonline.com/community/s/knowledge-base#All-All-DNO-Content-exact-online-sites

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

SetUserAgent sets the useragent provided on every communication with the Exact Online API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL