golexoffice

package module
v0.0.0-...-8dc7a2e Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

lexoffice API client

This is a fork of https://github.com/hostwithquantum/golexoffice.

It was customized to bit a bit more ergonomic and to use contexts.

Error handling and code was also made more idiomatic. See pkg.go.dev for docs.

The library is not 100% feature complete. I'm adding things I need. Feel free to contribute, it is very easy to add new endpoints.

Install

go get github.com/karitham/go-lexoffice

Useage

import (
    "fmt"
    "log"
    "os"

    lexoffice "github.com/karitham/go-lexoffice"
)

lc := lexoffice.NewClient(os.Getenv("LEXOFFICE_API_KEY"))
contacts, err := lc.GetContacts(context.TODO(), lexoffice.GetContactsParams{
    Name: "hitori gotoh"
})
if err != nil {
    log.Println(err.Error())
}

fmt.Println(contacts)

Documentation

Index

Constants

View Source
const DateFormat = "2006-01-02T15:04:05.000-07:00"

Variables

This section is empty.

Functions

func WithBaseUrl

func WithBaseUrl(baseUrl string) func(*Client)

func WithClient

func WithClient(client *http.Client) func(*Client)

func WithRate

func WithRate(opPerSecond int) func(*Client)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is to define the request data

func NewClient

func NewClient(token string, o ...func(*Client)) *Client

func (*Client) CreateContact

func (c *Client) CreateContact(ctx context.Context, body ContactBody) (ContactsResponse, error)

CreateContact creates a new contact <https://developers.lexoffice.io/docs/?shell#contacts-endpoint-create-a-contact>

func (*Client) DeeplinkInvoiceURL

func (c *Client) DeeplinkInvoiceURL(ctx context.Context, invoiceID string, edit bool) (string, error)

DeeplinkInvoiceURL is to get the deeplink url for a invoice <https://developers.lexoffice.io/docs/?shell#invoices-endpoint-deeplink-to-an-invoice>

func (*Client) DownloadFile

func (c *Client) DownloadFile(ctx context.Context, out io.Writer, id string) error

DownloadFile downloads a file <https://developers.lexoffice.io/docs/?shell#files-endpoint-download-a-file>

func (*Client) GetContact

func (c *Client) GetContact(ctx context.Context, id string) (ContactsContent, error)

GetContact is to get a contact by id <https://developers.lexoffice.io/docs/?shell#contacts-endpoint-retrieve-a-contact>

func (*Client) GetContacts

func (c *Client) GetContacts(ctx context.Context, p GetContactsParams) (ContactsReturn, error)

GetContacts is to get a list of all contacts <https://developers.lexoffice.io/docs/?shell#contacts-endpoint-filtering-contacts>

func (*Client) GetInvoice

func (c *Client) GetInvoice(ctx context.Context, id string) (InvoiceBody, error)

GetInvoice is to get a invoice <https://developers.lexoffice.io/docs/?shell#invoices-endpoint-retrieve-an-invoice>

func (*Client) RenderInvoicePDF

func (c *Client) RenderInvoicePDF(ctx context.Context, invoiceID string) (RenderResponse, error)

RenderInvoicePDF is to render a invoice as pdf <https://developers.lexoffice.io/docs/?shell#invoices-endpoint-render-an-invoice-document-pdf>

func (*Client) Request

func (c *Client) Request(path string) *requests.Builder

func (*Client) Requestf

func (c *Client) Requestf(path string, args ...any) *requests.Builder

func (*Client) UpdateContact

func (c *Client) UpdateContact(ctx context.Context, body ContactBody) (ContactsResponse, error)

UpdateContact updates existing contact <https://developers.lexoffice.io/docs/?shell#contacts-endpoint-update-a-contact>

type ContactBody

type ContactBody struct {
	Id             string                     `json:"id,omitempty"`
	Version        int                        `json:"version"`
	Roles          ContactBodyRoles           `json:"roles"`
	Company        *ContactBodyCompany        `json:"company,omitempty"`
	Person         *ContactBodyPerson         `json:"person,omitempty"`
	Addresses      *ContactBodyAddresses      `json:"addresses,omitempty"`
	EmailAddresses *ContactBodyEmailAddresses `json:"emailAddresses,omitempty"`
	PhoneNumbers   *ContactBodyPhoneNumbers   `json:"phoneNumbers,omitempty"`
	Note           string                     `json:"note"`
	Archived       bool                       `json:"archived,omitempty"`
}

ContactBody is to create a new contact

type ContactBodyAddresses

type ContactBodyAddresses struct {
	Billing  []*ContactBodyBilling  `json:"billing"`
	Shipping []*ContactBodyShipping `json:"shipping"`
}

type ContactBodyBilling

type ContactBodyBilling struct {
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	Zip         string `json:"zip"`
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
}

type ContactBodyCompany

type ContactBodyCompany struct {
	Name                 string                       `json:"name"`
	TaxNumber            string                       `json:"taxNumber,omitempty"`
	VatRegistrationId    string                       `json:"vatRegistrationId,omitempty"`
	AllowTaxFreeInvoices bool                         `json:"allowTaxFreeInvoices"`
	ContactPersons       []*ContactBodyContactPersons `json:"contactPersons"`
}

type ContactBodyContactPersons

type ContactBodyContactPersons struct {
	Salutation   string `json:"salutation"`
	FirstName    string `json:"firstName"`
	LastName     string `json:"lastName"`
	EmailAddress string `json:"emailAddress"`
	PhoneNumber  string `json:"phoneNumber"`
}

type ContactBodyCustomer

type ContactBodyCustomer struct {
	Number int `json:"number,omitempty"`
}

type ContactBodyEmailAddresses

type ContactBodyEmailAddresses struct {
	Business []string `json:"business"`
	Office   []string `json:"office"`
	Private  []string `json:"private"`
	Other    []string `json:"other"`
}

type ContactBodyPerson

type ContactBodyPerson struct {
	Salutation string `json:"salutation"`
	FirstName  string `json:"firstName"`
	LastName   string `json:"lastName"`
}

type ContactBodyPhoneNumbers

type ContactBodyPhoneNumbers struct {
	Business []string `json:"business"`
	Office   []string `json:"office"`
	Mobile   []string `json:"mobile"`
	Private  []string `json:"private"`
	Fax      []string `json:"fax"`
	Other    []string `json:"other"`
}

type ContactBodyRoles

type ContactBodyRoles struct {
	Customer *ContactBodyCustomer `json:"customer,omitempty"`
	Vendor   *ContactBodyVendor   `json:"vendor,omitempty"`
}

type ContactBodyShipping

type ContactBodyShipping struct {
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	Zip         string `json:"zip"`
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
}

type ContactBodyVendor

type ContactBodyVendor struct {
	Number int `json:"number,omitempty"`
}

type ContactsContent

type ContactsContent struct {
	Id             string                    `json:"id,omitempty"`
	Version        int                       `json:"version,omitempty"`
	Roles          ContactBodyRoles          `json:"roles"`
	Company        *ContactBodyCompany       `json:"company,omitempty"`
	Person         *ContactBodyPerson        `json:"person,omitempty"`
	Addresses      ContactBodyAddresses      `json:"addresses"`
	EmailAddresses ContactBodyEmailAddresses `json:"emailAddresses"`
	PhoneNumbers   ContactBodyPhoneNumbers   `json:"phoneNumbers"`
	Note           string                    `json:"note"`
	Archived       bool                      `json:"archived,omitempty"`
}

type ContactsResponse

type ContactsResponse struct {
	ID          string `json:"id"`
	ResourceUri string `json:"resourceUri"`
	CreatedDate string `json:"createdDate"`
	UpdatedDate string `json:"updatedDate"`
	Version     int    `json:"version"`
}

type ContactsReturn

type ContactsReturn struct {
	Content          []ContactsContent    `json:"content"`
	First            bool                 `json:"first"`
	Last             bool                 `json:"last"`
	TotalPages       int                  `json:"totalPages"`
	TotalElements    int                  `json:"totalElements"`
	NumberOfElements int                  `json:"numberOfElements"`
	Size             int                  `json:"size"`
	Number           int                  `json:"number"`
	Sort             []ContactsReturnSort `json:"sort"`
}

ContactsReturn is to decode json data

type ContactsReturnAddresses

type ContactsReturnAddresses struct {
	Billing  []ContactsReturnBilling  `json:"billing"`
	Shipping []ContactsReturnShipping `json:"shipping"`
}

type ContactsReturnBilling

type ContactsReturnBilling struct {
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	Zip         string `json:"zip"`
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
}

type ContactsReturnCompany

type ContactsReturnCompany struct {
	Name                 string                         `json:"name"`
	TaxNumber            string                         `json:"taxNumber"`
	VatRegistrationId    string                         `json:"vatRegistrationId"`
	AllowTaxFreeInvoices bool                           `json:"allowTaxFreeInvoices"`
	ContactPersons       []ContactsReturnContactPersons `json:"contactPersons"`
}

type ContactsReturnContactPersons

type ContactsReturnContactPersons struct {
	Salutation   string `json:"salutation"`
	FirstName    string `json:"firstName"`
	LastName     string `json:"lastName"`
	EmailAddress string `json:"emailAddress"`
	PhoneNumber  string `json:"phoneNumber"`
}

type ContactsReturnCustomer

type ContactsReturnCustomer struct {
	Number int `json:"number,omitempty"`
}

type ContactsReturnEmailAddresses

type ContactsReturnEmailAddresses struct {
	Business []string `json:"business"`
	Office   []string `json:"office"`
	Private  []string `json:"private"`
	Other    []string `json:"other"`
}

type ContactsReturnPhoneNumbers

type ContactsReturnPhoneNumbers struct {
	Business []string `json:"business"`
	Office   []string `json:"office"`
	Mobile   []string `json:"mobile"`
	Private  []string `json:"private"`
	Fax      []string `json:"fax"`
	Other    []string `json:"other"`
}

type ContactsReturnRoles

type ContactsReturnRoles struct {
	Customer ContactsReturnCustomer `json:"customer"`
	Vendor   ContactsReturnVendor   `json:"vendor"`
}

type ContactsReturnShipping

type ContactsReturnShipping struct {
	Supplement  string `json:"supplement"`
	Street      string `json:"street"`
	Zip         string `json:"zip"`
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
}

type ContactsReturnSort

type ContactsReturnSort struct {
	Property     string `json:"property"`
	Direction    string `json:"direction"`
	IgnoreCase   bool   `json:"ignoreCase"`
	NullHandling string `json:"nullHandling"`
	Ascending    bool   `json:"ascending"`
}

type ContactsReturnVendor

type ContactsReturnVendor struct {
	Number int `json:"number,omitempty"`
}

type CreateFileResponse

type CreateFileResponse struct {
	ID string `json:"id"`
}

type CreateInvoiceOptions

type CreateInvoiceOptions struct {
	Finalize                bool
	PrecedingSalesVoucherID string
	Body                    InvoiceBody
}

CreateInvoiceOptions represent the set of possible options when creating an invoice. if you provide a body, then the invoice will be created with the given body. if you provide a preceding sales voucher id, then the invoice will be created from the sales voucher with the given id.

type Date

type Date time.Time

func (Date) MarshalJSON

func (t Date) MarshalJSON() ([]byte, error)

func (*Date) UnmarshalJSON

func (t *Date) UnmarshalJSON(b []byte) error

type ErrorResponse

type ErrorResponse struct {
	Timestamp   Date   `json:"timestamp"`
	Status      int    `json:"status"`
	ErrorString string `json:"error"`
	Path        string `json:"path"`
	TraceID     string `json:"traceId"`
	Message     string `json:"message"`
	Details     []struct {
		Violation string `json:"violation"`
		Field     string `json:"field"`
		Message   string `json:"message"`
	} `json:"details"`
}

source: https://developers.lexoffice.io/docs/#error-codes-regular-error-response event-subscription, invoices

{
	"timestamp": "2017-05-11T17:12:31.233+02:00",
	"status": 406,
	"error": "Not Acceptable",
	"path": "/v1/invoices",
	"traceId": "90d78d0777be",
	"message": "Validation failed for request. Please see details list for specific causes.",
	"details": [
		{
			"violation": "NOTNULL",
			"field": "lineItems[0].unitPrice.taxRatePercentage",
			"message": "darf nicht leer sein"
		}
	]
}

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

func (ErrorResponse) String

func (e ErrorResponse) String() string

type GetContactsParams

type GetContactsParams struct {
	Page   omit.Val[int]
	Email  omit.Val[string]
	Name   omit.Val[string]
	Number omit.Val[int]

	// filtering goes like this:
	// 	- unspecified -> no filter
	// 	- true -> only customer
	// 	- false -> only non-customer
	Customer omit.Val[bool]

	// filtering goes like this:
	// 	- unspecified -> no filter
	// 	- true -> only vendor
	// 	- false -> only non-vendor
	Vendor omit.Val[bool]
}

type InvoiceBody

type InvoiceBody struct {
	ID                 string                        `json:"id,omitempty"`
	OrganizationID     string                        `json:"organizationId,omitempty"`
	CreateDate         Date                          `json:"createDate,omitempty"`
	UpdatedDate        Date                          `json:"updatedDate,omitempty"`
	Version            int                           `json:"version,omitempty"`
	Archived           bool                          `json:"archived,omitempty"`
	VoucherStatus      string                        `json:"voucherStatus,omitempty"`
	VoucherNumber      string                        `json:"voucherNumber,omitempty"`
	VoucherDate        Date                          `json:"voucherDate,omitempty"`
	DueDate            Date                          `json:"dueDate,omitempty"`
	Address            InvoiceBodyAddress            `json:"address,omitempty"`
	LineItems          []InvoiceBodyLineItems        `json:"lineItems,omitempty"`
	TotalPrice         InvoiceBodyTotalPrice         `json:"totalPrice,omitempty"`
	TaxAmounts         []InvoiceBodyTaxAmounts       `json:"taxAmounts,omitempty"`
	TaxConditions      InvoiceBodyTaxConditions      `json:"taxConditions,omitempty"`
	PaymentConditions  InvoiceBodyPaymentConditions  `json:"paymentConditions,omitempty"`
	ShippingConditions InvoiceBodyShippingConditions `json:"shippingConditions,omitempty"`
	Title              string                        `json:"title,omitempty"`
	Introduction       string                        `json:"introduction,omitempty"`
	Language           LanguageOption                `json:"language,omitempty"`
	Remark             string                        `json:"remark,omitempty"`
	Files              InvoiceBodyFiles              `json:"files,omitempty"`
}

InvoiceBody is to define body data

type InvoiceBodyAddress

type InvoiceBodyAddress struct {
	ContactID   string `json:"contactId,omitempty"`
	Name        string `json:"name,omitempty"`
	Supplement  string `json:"supplement,omitempty"`
	Street      string `json:"street,omitempty"`
	City        string `json:"city,omitempty"`
	Zip         string `json:"zip,omitempty"`
	CountryCode string `json:"countryCode,omitempty"`
}

type InvoiceBodyFiles

type InvoiceBodyFiles struct {
	ID string `json:"documentFileId,omitempty"`
}

type InvoiceBodyLineItems

type InvoiceBodyLineItems struct {
	Id                 string               `json:"id,omitempty"`
	Type               string               `json:"type,omitempty"`
	Name               string               `json:"name,omitempty"`
	Description        string               `json:"description,omitempty"`
	Quantity           float64              `json:"quantity,omitempty"`
	UnitName           string               `json:"unitName,omitempty"`
	UnitPrice          InvoiceBodyUnitPrice `json:"unitPrice,omitempty"`
	DiscountPercentage float64              `json:"discountPercentage,omitempty"`
	LineItemAmount     float64              `json:"lineItemAmount,omitempty"`
}

type InvoiceBodyPaymentConditions

type InvoiceBodyPaymentConditions struct {
	PaymentTermLabel          string                                         `json:"paymentTermLabel,omitempty"`
	PaymentTermDuration       int                                            `json:"paymentTermDuration,omitempty"`
	PaymentDiscountConditions omit.Val[InvoiceBodyPaymentDiscountConditions] `json:"paymentDiscountConditions,omitempty"`
}

type InvoiceBodyPaymentDiscountConditions

type InvoiceBodyPaymentDiscountConditions struct {
	DiscountPercentage int `json:"discountPercentage,omitempty"`
	DiscountRange      int `json:"discountRange,omitempty"`
}

type InvoiceBodyShippingConditions

type InvoiceBodyShippingConditions struct {
	ShippingDate    Date   `json:"shippingDate,omitempty"`
	ShippingEndDate Date   `json:"shippingEndDate,omitempty"`
	ShippingType    string `json:"shippingType,omitempty"`
}

type InvoiceBodyTaxAmounts

type InvoiceBodyTaxAmounts struct {
	TaxRatePercentage float64         `json:"taxRatePercentage,omitempty"`
	TaxAmount         decimal.Decimal `json:"taxAmount,omitempty"`
	Amount            decimal.Decimal `json:"amount,omitempty"`
}

type InvoiceBodyTaxConditions

type InvoiceBodyTaxConditions struct {
	TaxType     string `json:"taxType,omitempty"`
	TaxTypeNote string `json:"taxTypeNote,omitempty"`
}

type InvoiceBodyTotalPrice

type InvoiceBodyTotalPrice struct {
	Currency                string                    `json:"currency,omitempty"`
	TotalNetAmount          decimal.Decimal           `json:"totalNetAmount,omitempty"`
	TotalGrossAmount        decimal.Decimal           `json:"totalGrossAmount,omitempty"`
	TaxRatePercentage       float64                   `json:"taxRatePercentage,omitempty"`
	TotalTaxAmount          decimal.Decimal           `json:"totalTaxAmount,omitempty"`
	TotalDiscountAbsolute   omit.Val[decimal.Decimal] `json:"totalDiscountAbsolute,omitempty"`
	TotalDiscountPercentage omit.Val[float64]         `json:"totalDiscountPercentage,omitempty"`
}

type InvoiceBodyUnitPrice

type InvoiceBodyUnitPrice struct {
	Currency          string          `json:"currency,omitempty"`
	NetAmount         decimal.Decimal `json:"netAmount,omitempty"`
	GrossAmount       decimal.Decimal `json:"grossAmount,omitempty"`
	TaxRatePercentage float64         `json:"taxRatePercentage,omitempty"`
}

type InvoiceResponse

type InvoiceResponse struct {
	ID          string `json:"id,omitempty"`
	ResourceURI string `json:"resourceUri,omitempty"`
	CreatedDate Date   `json:"createdDate,omitempty"`
	UpdatedDate Date   `json:"updatedDate,omitempty"`
	Version     int    `json:"version,omitempty"`
}

InvoiceResponse is to decode json data

type LanguageOption

type LanguageOption string
const (
	LanguageOptionEN LanguageOption = "en"
	LanguageOptionDE LanguageOption = "de"
)

type LegacyErrorResponse

type LegacyErrorResponse struct {
	RequestID string `json:"requestId"`
	IssueList []struct {
		Key    string `json:"i18nKey"`
		Source string `json:"source"`
		Type   string `json:"type"`
	} `json:"IssueList"`
}

source: https://developers.lexoffice.io/docs/#error-codes-legacy-error-response files, profile, contacts

{
	"requestId":"3fb21ee4-ad26-4e2f-82af-a1197af02d08",
	"IssueList":[
		{"i18nKey":"invalid_value","source":"company and person","type":"validation_failure"},
		{"i18nKey":"missing_entity","source":"company.name","type":"validation_failure"}
	]
}

func (LegacyErrorResponse) Error

func (e LegacyErrorResponse) Error() string

func (LegacyErrorResponse) String

func (e LegacyErrorResponse) String() string

type RenderResponse

type RenderResponse struct {
	ID string `json:"documentFileId,omitempty"`
}

Jump to

Keyboard shortcuts

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