api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 15 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.

It tries the MoneyForward shape (`{"errors":[{"code":..,"message":..}]}`) first and falls back to the OAuth-style shape used by 401/403 token errors (`{"error":"insufficient_scope","error_description":"...", "error_uri":"..."}`). Anything else is preserved verbatim in RawResponse.

func (*APIError) Error

func (e *APIError) Error() string

type BillingListParams added in v0.2.0

type BillingListParams struct {
	Page           *int
	PerPage        *int
	RangeKey       string
	From           string
	To             string
	Q              string
	PartnerID      string
	DocumentNumber string
	Status         string
	PartnerName    string
	Tags           string
}

BillingListParams holds query parameters for `GET /api/v3/billings`.

status / tags / document_number / partner_name accept comma-separated values per the spec; we therefore keep them as raw strings rather than slices to avoid encoding ambiguity. Per the spec, when `q` is supplied the field-specific filters are ignored — callers should reject that combination at the CLI layer.

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 for the MoneyForward Accounting API.

func NewInvoiceClient added in v0.2.0

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

NewInvoiceClient creates a new API client for the MoneyForward Invoice API.

The base URL is derived from cfg.InvoiceBaseURL after passing through config.NormalizeInvoiceBaseURL: a strict origin-only validation that trims trailing slashes / "/api/v3" suffixes and rejects malformed values. An empty cfg.InvoiceBaseURL falls back to the production default (config.DefaultInvoiceBaseURL); any other invalid value is returned as a hard error rather than silently rewritten, so a typo in a test fixture cannot accidentally route requests to production.

Resource methods on the returned *Client must build their request path including the "/api/v3" prefix (the spec uses servers.url for the prefix; CLI HTTP paths concatenate it explicitly to mirror the accounting client style).

func (*Client) BuildCreateBillingRequest added in v0.2.0

func (c *Client) BuildCreateBillingRequest(req *invoicemodel.CreateBillingRequest) (*DryRunOutput, error)

BuildCreateBillingRequest is a dry-run helper.

func (*Client) BuildDeleteBillingRequest added in v0.2.0

func (c *Client) BuildDeleteBillingRequest(id string) (*DryRunOutput, error)

BuildDeleteBillingRequest is a dry-run helper.

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) BuildUpdateBillingRequest added in v0.2.0

func (c *Client) BuildUpdateBillingRequest(id string, req *invoicemodel.UpdateBillingRequest) (*DryRunOutput, error)

BuildUpdateBillingRequest is a dry-run helper.

func (*Client) CreateBilling added in v0.2.0

func (c *Client) CreateBilling(ctx context.Context, req *invoicemodel.CreateBillingRequest) ([]byte, error)

CreateBilling creates a new invoice using the invoice-template endpoint (this is the documented invoice-system-compliant create). POST /api/v3/invoice_template_billings

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) DeleteBilling added in v0.2.0

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

DeleteBilling deletes a billing by ID. DELETE /api/v3/billings/{billing_id}

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) GetBilling added in v0.2.0

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

GetBilling retrieves a single billing by ID. GET /api/v3/billings/{billing_id}

func (*Client) GetBillings added in v0.2.0

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

GetBillings retrieves a paginated list of billings. GET /api/v3/billings

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) GetItem added in v0.2.0

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

GetItem retrieves a single item by ID. GET /api/v3/items/{item_id}

func (*Client) GetItems added in v0.2.0

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

GetItems retrieves a paginated list of items. GET /api/v3/items

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) GetPartner added in v0.2.0

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

GetPartner retrieves a single partner by ID. GET /api/v3/partners/{partner_id}

func (*Client) GetPartnerDepartment added in v0.2.0

func (c *Client) GetPartnerDepartment(ctx context.Context, partnerID, departmentID string) ([]byte, error)

GetPartnerDepartment retrieves a single department under a partner. GET /api/v3/partners/{partner_id}/departments/{department_id}

func (*Client) GetPartnerDepartments added in v0.2.0

func (c *Client) GetPartnerDepartments(ctx context.Context, partnerID string, params DepartmentListParams) ([]byte, error)

GetPartnerDepartments retrieves the departments belonging to a partner. GET /api/v3/partners/{partner_id}/departments

func (*Client) GetPartners added in v0.2.0

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

GetPartners retrieves a paginated list of partners. GET /api/v3/partners

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) UpdateBilling added in v0.2.0

func (c *Client) UpdateBilling(ctx context.Context, id string, req *invoicemodel.UpdateBillingRequest) ([]byte, error)

UpdateBilling updates an existing billing. PUT /api/v3/billings/{billing_id}

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 DepartmentListParams added in v0.2.0

type DepartmentListParams struct {
	Page    *int
	PerPage *int
}

DepartmentListParams holds query parameters for `GET /api/v3/partners/{partner_id}/departments`.

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 ItemListParams added in v0.2.0

type ItemListParams struct {
	Name    string
	Code    string
	Page    *int
	PerPage *int
}

ItemListParams holds query parameters for `GET /api/v3/items`.

Both Name and Code accept comma-separated values per the spec.

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 PartnerListParams added in v0.2.0

type PartnerListParams struct {
	Name       string
	Code       string
	NameKana   string
	PartnerPic string
	OfficePic  string
	Page       *int
	PerPage    *int
}

PartnerListParams holds query parameters for `GET /api/v3/partners`.

All filter fields accept comma-separated values per the spec.

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