Documentation
¶
Index ¶
- func FilterFields(data []byte, fields string) ([]byte, error)
- type APIError
- type BillingListParams
- type Client
- func (c *Client) BuildCreateBillingRequest(req *invoicemodel.CreateBillingRequest) (*DryRunOutput, error)
- func (c *Client) BuildDeleteBillingRequest(id string) (*DryRunOutput, error)
- func (c *Client) BuildRequest(method, path string, query url.Values, body any) (*DryRunOutput, error)
- func (c *Client) BuildUpdateBillingRequest(id string, req *invoicemodel.UpdateBillingRequest) (*DryRunOutput, error)
- func (c *Client) CreateBilling(ctx context.Context, req *invoicemodel.CreateBillingRequest) ([]byte, error)
- func (c *Client) CreateJournal(ctx context.Context, req *model.CRUDJournalRequest) ([]byte, error)
- func (c *Client) CreateTradePartners(ctx context.Context, req *model.PostTradePartnersRequest) ([]byte, error)
- func (c *Client) CreateTransactions(ctx context.Context, req *model.PostTransactionsRequest) ([]byte, error)
- func (c *Client) CreateVouchers(ctx context.Context, req *model.PostVouchersRequest) ([]byte, error)
- func (c *Client) Delete(ctx context.Context, path string, body any) ([]byte, error)
- func (c *Client) DeleteBilling(ctx context.Context, id string) error
- func (c *Client) DeleteJournal(ctx context.Context, id string) error
- func (c *Client) DeleteVouchers(ctx context.Context, req *model.DeleteVouchersRequest) error
- func (c *Client) Do(ctx context.Context, method, path string, query url.Values, body any) ([]byte, error)
- func (c *Client) Get(ctx context.Context, path string, query url.Values) ([]byte, error)
- func (c *Client) GetAccounts(ctx context.Context, available *bool) ([]byte, error)
- func (c *Client) GetBilling(ctx context.Context, id string) ([]byte, error)
- func (c *Client) GetBillings(ctx context.Context, params BillingListParams) ([]byte, error)
- func (c *Client) GetConnectedAccounts(ctx context.Context) ([]byte, error)
- func (c *Client) GetDepartments(ctx context.Context) ([]byte, error)
- func (c *Client) GetItem(ctx context.Context, id string) ([]byte, error)
- func (c *Client) GetItems(ctx context.Context, params ItemListParams) ([]byte, error)
- func (c *Client) GetJournal(ctx context.Context, id string) ([]byte, error)
- func (c *Client) GetJournals(ctx context.Context, params JournalListParams) ([]byte, error)
- func (c *Client) GetOffice(ctx context.Context) ([]byte, error)
- func (c *Client) GetPartner(ctx context.Context, id string) ([]byte, error)
- func (c *Client) GetPartnerDepartment(ctx context.Context, partnerID, departmentID string) ([]byte, error)
- func (c *Client) GetPartnerDepartments(ctx context.Context, partnerID string, params DepartmentListParams) ([]byte, error)
- func (c *Client) GetPartners(ctx context.Context, params PartnerListParams) ([]byte, error)
- func (c *Client) GetSubAccounts(ctx context.Context, accountID string) ([]byte, error)
- func (c *Client) GetTaxes(ctx context.Context, available *bool) ([]byte, error)
- func (c *Client) GetTradePartners(ctx context.Context, available *bool) ([]byte, error)
- func (c *Client) GetTransitionBS(ctx context.Context, params TransitionParams) ([]byte, error)
- func (c *Client) GetTransitionPL(ctx context.Context, params TransitionParams) ([]byte, error)
- func (c *Client) GetTrialBalanceBS(ctx context.Context, params TBParams) ([]byte, error)
- func (c *Client) GetTrialBalancePL(ctx context.Context, params TBParams) ([]byte, error)
- func (c *Client) Post(ctx context.Context, path string, body any) ([]byte, error)
- func (c *Client) Put(ctx context.Context, path string, body any) ([]byte, error)
- func (c *Client) UpdateBilling(ctx context.Context, id string, req *invoicemodel.UpdateBillingRequest) ([]byte, error)
- func (c *Client) UpdateJournal(ctx context.Context, id string, req *model.CRUDJournalRequest) ([]byte, error)
- type DepartmentListParams
- type DryRunOutput
- type ItemListParams
- type JournalListParams
- type PartnerListParams
- type TBParams
- type TransitionParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterFields ¶
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 ¶
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.
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 NewInvoiceClient ¶ added in v0.2.0
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 ¶
CreateJournal creates a new journal entry. POST /api/v3/journals
func (*Client) CreateTradePartners ¶
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) DeleteBilling ¶ added in v0.2.0
DeleteBilling deletes a billing by ID. DELETE /api/v3/billings/{billing_id}
func (*Client) DeleteJournal ¶
DeleteJournal deletes a journal entry by ID. DELETE /api/v3/journals/{id}
func (*Client) DeleteVouchers ¶
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) GetAccounts ¶
func (*Client) GetBilling ¶ added in v0.2.0
GetBilling retrieves a single billing by ID. GET /api/v3/billings/{billing_id}
func (*Client) GetBillings ¶ added in v0.2.0
GetBillings retrieves a paginated list of billings. GET /api/v3/billings
func (*Client) GetConnectedAccounts ¶
GetConnectedAccounts retrieves the list of connected accounts. GET /api/v3/connected_accounts
func (*Client) GetDepartments ¶
GetDepartments retrieves the list of departments. GET /api/v3/departments
func (*Client) GetItem ¶ added in v0.2.0
GetItem retrieves a single item by ID. GET /api/v3/items/{item_id}
func (*Client) GetItems ¶ added in v0.2.0
GetItems retrieves a paginated list of items. GET /api/v3/items
func (*Client) GetJournal ¶
GetJournal retrieves a single journal by ID. GET /api/v3/journals/{id}
func (*Client) GetJournals ¶
GetJournals retrieves a list of journals with optional filters. GET /api/v3/journals
func (*Client) GetPartner ¶ added in v0.2.0
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
GetPartners retrieves a paginated list of partners. GET /api/v3/partners
func (*Client) GetSubAccounts ¶
GetSubAccounts retrieves the list of sub-accounts for a given account. GET /api/v3/sub_accounts
func (*Client) GetTradePartners ¶
func (*Client) GetTransitionBS ¶
GetTransitionBS retrieves the balance sheet transition report. GET /api/v3/reports/transition_bs
func (*Client) GetTransitionPL ¶
GetTransitionPL retrieves the profit and loss transition report. GET /api/v3/reports/transition_pl
func (*Client) GetTrialBalanceBS ¶
GetTrialBalanceBS retrieves the trial balance (balance sheet). GET /api/v3/reports/trial_balance_bs
func (*Client) GetTrialBalancePL ¶
GetTrialBalancePL retrieves the trial balance (profit and loss). GET /api/v3/reports/trial_balance_pl
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
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
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.