api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterFields

func FilterFields(data []byte, fields string) ([]byte, error)

FilterFields filters JSON data to include only the specified dotted field paths. The fields parameter is a comma-separated list of dotted paths like "accounts.id,accounts.name". For array fields, the filter is applied to each element. If a field path doesn't exist, it is silently skipped.

Types

type APIError

type APIError struct {
	StatusCode  int
	Operation   string
	Errors      []model.ErrorDetail
	RawResponse string
}

APIError represents an error response from the MoneyForward API.

func ParseErrorResponse

func ParseErrorResponse(statusCode int, body []byte) *APIError

ParseErrorResponse parses an API error response body into an APIError.

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client is an HTTP client for the MoneyForward Accounting API.

func NewClient

func NewClient(cfg *config.Config, debug bool) *Client

NewClient creates a new API client.

func (*Client) BuildRequest

func (c *Client) BuildRequest(method, path string, query url.Values, body any) (*DryRunOutput, error)

BuildRequest constructs a DryRunOutput without making any network calls. For bodies containing "file_data" fields, base64 values are truncated.

func (*Client) CreateJournal

func (c *Client) CreateJournal(ctx context.Context, req *model.CRUDJournalRequest) ([]byte, error)

CreateJournal creates a new journal entry. POST /api/v3/journals

func (*Client) CreateTradePartners

func (c *Client) CreateTradePartners(ctx context.Context, req *model.PostTradePartnersRequest) ([]byte, error)

func (*Client) CreateTransactions

func (c *Client) CreateTransactions(ctx context.Context, req *model.PostTransactionsRequest) ([]byte, error)

CreateTransactions creates transactions for a connected account. POST /api/v3/transactions

func (*Client) CreateVouchers

func (c *Client) CreateVouchers(ctx context.Context, req *model.PostVouchersRequest) ([]byte, error)

CreateVouchers uploads voucher files. POST /api/v3/vouchers

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, body any) ([]byte, error)

Delete is a convenience method for DELETE requests.

func (*Client) DeleteJournal

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

DeleteJournal deletes a journal entry by ID. DELETE /api/v3/journals/{id}

func (*Client) DeleteVouchers

func (c *Client) DeleteVouchers(ctx context.Context, req *model.DeleteVouchersRequest) error

DeleteVouchers deletes a voucher file. DELETE /api/v3/vouchers

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, query url.Values, body any) ([]byte, error)

Do executes an HTTP request against the API with authentication, retry, and error handling.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, query url.Values) ([]byte, error)

Get is a convenience method for GET requests.

func (*Client) GetAccounts

func (c *Client) GetAccounts(ctx context.Context, available *bool) ([]byte, error)

func (*Client) GetConnectedAccounts

func (c *Client) GetConnectedAccounts(ctx context.Context) ([]byte, error)

GetConnectedAccounts retrieves the list of connected accounts. GET /api/v3/connected_accounts

func (*Client) GetDepartments

func (c *Client) GetDepartments(ctx context.Context) ([]byte, error)

GetDepartments retrieves the list of departments. GET /api/v3/departments

func (*Client) GetJournal

func (c *Client) GetJournal(ctx context.Context, id string) ([]byte, error)

GetJournal retrieves a single journal by ID. GET /api/v3/journals/{id}

func (*Client) GetJournals

func (c *Client) GetJournals(ctx context.Context, params JournalListParams) ([]byte, error)

GetJournals retrieves a list of journals with optional filters. GET /api/v3/journals

func (*Client) GetOffice

func (c *Client) GetOffice(ctx context.Context) ([]byte, error)

GetOffice retrieves office information. GET /api/v3/offices

func (*Client) GetSubAccounts

func (c *Client) GetSubAccounts(ctx context.Context, accountID string) ([]byte, error)

GetSubAccounts retrieves the list of sub-accounts for a given account. GET /api/v3/sub_accounts

func (*Client) GetTaxes

func (c *Client) GetTaxes(ctx context.Context, available *bool) ([]byte, error)

func (*Client) GetTradePartners

func (c *Client) GetTradePartners(ctx context.Context, available *bool) ([]byte, error)

func (*Client) GetTransitionBS

func (c *Client) GetTransitionBS(ctx context.Context, params TransitionParams) ([]byte, error)

GetTransitionBS retrieves the balance sheet transition report. GET /api/v3/reports/transition_bs

func (*Client) GetTransitionPL

func (c *Client) GetTransitionPL(ctx context.Context, params TransitionParams) ([]byte, error)

GetTransitionPL retrieves the profit and loss transition report. GET /api/v3/reports/transition_pl

func (*Client) GetTrialBalanceBS

func (c *Client) GetTrialBalanceBS(ctx context.Context, params TBParams) ([]byte, error)

GetTrialBalanceBS retrieves the trial balance (balance sheet). GET /api/v3/reports/trial_balance_bs

func (*Client) GetTrialBalancePL

func (c *Client) GetTrialBalancePL(ctx context.Context, params TBParams) ([]byte, error)

GetTrialBalancePL retrieves the trial balance (profit and loss). GET /api/v3/reports/trial_balance_pl

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body any) ([]byte, error)

Post is a convenience method for POST requests.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body any) ([]byte, error)

Put is a convenience method for PUT requests.

func (*Client) UpdateJournal

func (c *Client) UpdateJournal(ctx context.Context, id string, req *model.CRUDJournalRequest) ([]byte, error)

UpdateJournal updates an existing journal entry. PUT /api/v3/journals/{id}

type DryRunOutput

type DryRunOutput struct {
	Method string          `json:"method"`
	URL    string          `json:"url"`
	Body   json.RawMessage `json:"body,omitempty"`
}

DryRunOutput represents the details of a request without executing it.

type JournalListParams

type JournalListParams struct {
	StartDate  string
	EndDate    string
	AccountID  string
	IsRealized *bool
	Page       *int
	PerPage    *int
}

JournalListParams holds query parameters for listing journals.

type TBParams

type TBParams struct {
	FiscalYear      *int
	StartMonth      *int
	EndMonth        *int
	StartDate       string
	EndDate         string
	WithSubAccounts *bool
	IncludeTax      *bool
	JournalTypes    []string
}

TBParams holds query parameters for trial balance reports.

type TransitionParams

type TransitionParams struct {
	Type            string
	FiscalYear      *int
	StartMonth      *int
	EndMonth        *int
	WithSubAccounts *bool
	IncludeTax      *bool
}

TransitionParams holds query parameters for transition reports.

Jump to

Keyboard shortcuts

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