# README
Accounting
Codat's Accounting API is a flexible API for pulling and pushing up-to-date accounting data to your customer's accounting software. It gives you a simple way to view, create, update adn delete data without having to worry about each platform's specific complexities.
Summary
Accounting API: > ### New to Codat?
Our Accounting API reference is relevant only to our existing clients. Please reach out to your Codat contact so that we can find the right product for you.
A flexible API for pulling accounting data, normalized and aggregated from 20 accounting integrations.
Standardize how you connect to your customers’ accounting software. View, create, update, and delete data in the same way for all the leading accounting software.
Endpoints
Endpoints | Description |
---|---|
Accounts | Access standardized Accounts from linked accounting software. |
Account transactions | Access standardized Account transactions from linked accounting software. |
Bank accounts | Access standardized Bank accounts from linked accounting software. |
Bank account transactions | Access standardized Bank transactions for bank accounts from linked accounting software. |
Bills | Access standardized Bills from linked accounting software. |
Bill credit notes | Access standardized Bill credit notes from linked accounting software. |
Bill payments | Access standardized Bill payments from linked accounting software. |
Credit notes | Access standardized Credit notes from linked accounting software. |
Customers | Access standardized Customers from linked accounting software. |
Direct costs | Access standardized Direct costs from linked accounting software. |
Direct incomes | Access standardized Direct incomes from linked accounting software. |
Company info | Access standardized Company info from linked accounting software. |
Invoices | Access standardized Invoices from linked accounting software. |
Item receipts | Access standardized Item receipts from linked accounting software. |
Items | Access standardized Items from linked accounting software. |
Journals | Access standardized Journals from linked accounting software. |
Journal entries | Access standardized Journal entries from linked accounting software. |
Payments | Access standardized Payments from linked accounting software. |
Payment methods | Access standardized Payment methods from linked accounting software. |
Purchase orders | Access standardized Purchase orders from linked accounting software. |
Sales orders | Access standardized Sales orders from linked accounting software. |
Suppliers | Access standardized Suppliers from linked accounting software. |
Tax rates | Access standardized Tax rates from linked accounting software. |
Tracking categories | Access standardized Tracking categories from linked accounting software. |
Transfers | Access standardized Transfers from linked accounting software. |
Reports | Access standardized Reports from linked accounting software. |
Table of Contents
- SDK Installation
- SDK Example Usage
- Available Resources and Operations
- Retries
- Error Handling
- Server Selection
- Custom HTTP Client
- Authentication
- Special Types
SDK Installation
To add the SDK as a dependency to your project:
go get github.com/codatio/client-sdk-go/previous-versions/accounting
Example Usage
SDK Example Usage
Example
package main
import (
"context"
"github.com/codatio/client-sdk-go/previous-versions/accounting"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/operations"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/shared"
"log"
)
func main() {
s := accounting.New(
accounting.WithSecurity(shared.Security{
AuthHeader: "Basic BASE_64_ENCODED(API_KEY)",
}),
)
ctx := context.Background()
res, err := s.AccountTransactions.Get(ctx, operations.GetAccountTransactionRequest{
AccountTransactionID: "<value>",
CompanyID: "8a210b68-6988-11ed-a1eb-0242ac120002",
ConnectionID: "2e9d2c44-f675-40ba-8049-353bfcb5e171",
})
if err != nil {
log.Fatal(err)
}
if res.AccountTransaction != nil {
// handle response
}
}
Available Resources and Operations
Available methods
Accounts
- Create - Create account
- Get - Get account
- GetCreateModel - Get create account model
- List - List accounts
AccountTransactions
BankAccounts
- Create - Create bank account
- Get - Get bank account
- GetCreateUpdateModel - Get create/update bank account model
- List - List bank accounts
- Update - Update bank account
BankAccountTransactions
- Create - Create bank account transactions
- GetCreateModel - Get create bank account transactions model
- List - List bank account transactions
BillCreditNotes
- Create - Create bill credit note
- Get - Get bill credit note
- GetCreateUpdateModel - Get create/update bill credit note model
- List - List bill credit notes
- Update - Update bill credit note
- UploadAttachment - Upload bill credit note attachment
BillPayments
- Create - Create bill payments
- Delete - Delete bill payment
- Get - Get bill payment
- GetCreateModel - Get create bill payment model
- List - List bill payments
Bills
- Create - Create bill
- Delete - Delete bill
- DownloadAttachment - Download bill attachment
- Get - Get bill
- GetAttachment - Get bill attachment
- GetCreateUpdateModel - Get create/update bill model
- List - List bills
- ListAttachments - List bill attachments
- Update - Update bill
- UploadAttachment - Upload bill attachment
CompanyInfo
CreditNotes
- Create - Create credit note
- Get - Get credit note
- GetCreateUpdateModel - Get create/update credit note model
- List - List credit notes
- Update - Update credit note
Customers
- Create - Create customer
- DownloadAttachment - Download customer attachment
- Get - Get customer
- GetAttachment - Get customer attachment
- GetCreateUpdateModel - Get create/update customer model
- List - List customers
- ListAttachments - List customer attachments
- Update - Update customer
DirectCosts
- Create - Create direct cost
- Delete - Delete direct cost
- DownloadAttachment - Download direct cost attachment
- Get - Get direct cost
- GetAttachment - Get direct cost attachment
- GetCreateModel - Get create direct cost model
- List - List direct costs
- ListAttachments - List direct cost attachments
- UploadAttachment - Upload direct cost attachment
DirectIncomes
- Create - Create direct income
- DownloadAttachment - Download direct income attachment
- Get - Get direct income
- GetAttachment - Get direct income attachment
- GetCreateModel - Get create direct income model
- List - List direct incomes
- ListAttachments - List direct income attachments
- UploadAttachment - Create direct income attachment
Invoices
- Create - Create invoice
- Delete - Delete invoice
- DownloadAttachment - Download invoice attachment
- DownloadPdf - Get invoice as PDF
- Get - Get invoice
- GetAttachment - Get invoice attachment
- GetCreateUpdateModel - Get create/update invoice model
- List - List invoices
- ListAttachments - List invoice attachments
- Update - Update invoice
- UploadAttachment - Upload invoice attachment
ItemReceipts
Items
- Create - Create item
- Get - Get item
- GetCreateModel - Get create item model
- List - List items
JournalEntries
- Create - Create journal entry
- Delete - Delete journal entry
- Get - Get journal entry
- GetCreateModel - Get create journal entry model
- List - List journal entries
Journals
- Create - Create journal
- Get - Get journal
- GetCreateModel - Get create journal model
- List - List journals
PaymentMethods
Payments
- Create - Create payment
- Get - Get payment
- GetCreateModel - Get create payment model
- List - List payments
- Payments - List payments
PurchaseOrders
- Create - Create purchase order
- DownloadAttachment - Download purchase order attachment
- DownloadPurchaseOrderPdf - Download purchase order as PDF
- Get - Get purchase order
- GetAttachment - Get purchase order attachment
- GetCreateUpdateModel - Get create/update purchase order model
- List - List purchase orders
- ListAttachments - List purchase order attachments
- Update - Update purchase order
Reports
- GetAgedCreditorsReport - Aged creditors report
- GetAgedDebtorsReport - Aged debtors report
- GetBalanceSheet - Get balance sheet
- GetCashFlowStatement - Get cash flow statement
- GetProfitAndLoss - Get profit and loss
- IsAgedCreditorsReportAvailable - Aged creditors report available
- IsAgedDebtorReportAvailable - Aged debtors report available
SalesOrders
Suppliers
- Create - Create supplier
- DownloadAttachment - Download supplier attachment
- Get - Get supplier
- GetAttachment - Get supplier attachment
- GetCreateUpdateModel - Get create/update supplier model
- List - List suppliers
- ListAttachments - List supplier attachments
- Update - Update supplier
TaxRates
TrackingCategories
Transfers
- Create - Create transfer
- Get - Get transfer
- GetCreateModel - Get create transfer model
- List - List transfers
- UploadAttachment - Upload transfer attachment
Special Types
This SDK defines the following custom types to assist with marshalling and unmarshalling data.
Date
types.Date
is a wrapper around time.Time that allows for JSON marshaling a date string formatted as "2006-01-02".
Usage
d1 := types.NewDate(time.Now()) // returns *types.Date
d2 := types.DateFromTime(time.Now()) // returns types.Date
d3, err := types.NewDateFromString("2019-01-01") // returns *types.Date, error
d4, err := types.DateFromString("2019-01-01") // returns types.Date, error
d5 := types.MustNewDateFromString("2019-01-01") // returns *types.Date and panics on error
d6 := types.MustDateFromString("2019-01-01") // returns types.Date and panics on error
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retry.Config
object to the call by using the WithRetries
option:
package main
import (
"context"
"github.com/codatio/client-sdk-go/previous-versions/accounting"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/operations"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/shared"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/retry"
"log"
"pkg/models/operations"
)
func main() {
s := accounting.New(
accounting.WithSecurity(shared.Security{
AuthHeader: "Basic BASE_64_ENCODED(API_KEY)",
}),
)
ctx := context.Background()
res, err := s.AccountTransactions.Get(ctx, operations.GetAccountTransactionRequest{
AccountTransactionID: "<value>",
CompanyID: "8a210b68-6988-11ed-a1eb-0242ac120002",
ConnectionID: "2e9d2c44-f675-40ba-8049-353bfcb5e171",
}, operations.WithRetries(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}))
if err != nil {
log.Fatal(err)
}
if res.AccountTransaction != nil {
// handle response
}
}
If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig
option at SDK initialization:
package main
import (
"context"
"github.com/codatio/client-sdk-go/previous-versions/accounting"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/operations"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/shared"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/retry"
"log"
)
func main() {
s := accounting.New(
accounting.WithRetryConfig(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}),
accounting.WithSecurity(shared.Security{
AuthHeader: "Basic BASE_64_ENCODED(API_KEY)",
}),
)
ctx := context.Background()
res, err := s.AccountTransactions.Get(ctx, operations.GetAccountTransactionRequest{
AccountTransactionID: "<value>",
CompanyID: "8a210b68-6988-11ed-a1eb-0242ac120002",
ConnectionID: "2e9d2c44-f675-40ba-8049-353bfcb5e171",
})
if err != nil {
log.Fatal(err)
}
if res.AccountTransaction != nil {
// handle response
}
}
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.ErrorMessage | 401,402,403,404,409,429,500,503 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
Example
package main
import (
"context"
"errors"
"github.com/codatio/client-sdk-go/previous-versions/accounting"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/operations"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/sdkerrors"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/shared"
"log"
)
func main() {
s := accounting.New(
accounting.WithSecurity(shared.Security{
AuthHeader: "Basic BASE_64_ENCODED(API_KEY)",
}),
)
ctx := context.Background()
res, err := s.AccountTransactions.Get(ctx, operations.GetAccountTransactionRequest{
AccountTransactionID: "<value>",
CompanyID: "8a210b68-6988-11ed-a1eb-0242ac120002",
ConnectionID: "2e9d2c44-f675-40ba-8049-353bfcb5e171",
})
if err != nil {
var e *sdkerrors.ErrorMessage
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *sdkerrors.SDKError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
Server Selection
Select Server by Index
You can override the default server globally using the WithServerIndex
option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://api.codat.io | None |
Example
package main
import (
"context"
"github.com/codatio/client-sdk-go/previous-versions/accounting"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/operations"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/shared"
"log"
)
func main() {
s := accounting.New(
accounting.WithServerIndex(0),
accounting.WithSecurity(shared.Security{
AuthHeader: "Basic BASE_64_ENCODED(API_KEY)",
}),
)
ctx := context.Background()
res, err := s.AccountTransactions.Get(ctx, operations.GetAccountTransactionRequest{
AccountTransactionID: "<value>",
CompanyID: "8a210b68-6988-11ed-a1eb-0242ac120002",
ConnectionID: "2e9d2c44-f675-40ba-8049-353bfcb5e171",
})
if err != nil {
log.Fatal(err)
}
if res.AccountTransaction != nil {
// handle response
}
}
Override Server URL Per-Client
The default server can also be overridden globally using the WithServerURL
option when initializing the SDK client instance. For example:
package main
import (
"context"
"github.com/codatio/client-sdk-go/previous-versions/accounting"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/operations"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/shared"
"log"
)
func main() {
s := accounting.New(
accounting.WithServerURL("https://api.codat.io"),
accounting.WithSecurity(shared.Security{
AuthHeader: "Basic BASE_64_ENCODED(API_KEY)",
}),
)
ctx := context.Background()
res, err := s.AccountTransactions.Get(ctx, operations.GetAccountTransactionRequest{
AccountTransactionID: "<value>",
CompanyID: "8a210b68-6988-11ed-a1eb-0242ac120002",
ConnectionID: "2e9d2c44-f675-40ba-8049-353bfcb5e171",
})
if err != nil {
log.Fatal(err)
}
if res.AccountTransaction != nil {
// handle response
}
}
Custom HTTP Client
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
The built-in net/http
client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
import (
"net/http"
"time"
"github.com/myorg/your-go-sdk"
)
var (
httpClient = &http.Client{Timeout: 30 * time.Second}
sdkClient = sdk.New(sdk.WithClient(httpClient))
)
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
AuthHeader | apiKey | API key |
You can configure it using the WithSecurity
option when initializing the SDK client instance. For example:
package main
import (
"context"
"github.com/codatio/client-sdk-go/previous-versions/accounting"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/operations"
"github.com/codatio/client-sdk-go/previous-versions/accounting/pkg/models/shared"
"log"
)
func main() {
s := accounting.New(
accounting.WithSecurity(shared.Security{
AuthHeader: "Basic BASE_64_ENCODED(API_KEY)",
}),
)
ctx := context.Background()
res, err := s.AccountTransactions.Get(ctx, operations.GetAccountTransactionRequest{
AccountTransactionID: "<value>",
CompanyID: "8a210b68-6988-11ed-a1eb-0242ac120002",
ConnectionID: "2e9d2c44-f675-40ba-8049-353bfcb5e171",
})
if err != nil {
log.Fatal(err)
}
if res.AccountTransaction != nil {
// handle response
}
}
Support
If you encounter any challenges while utilizing our SDKs, please don't hesitate to reach out for assistance. You can raise any issues by contacting your dedicated Codat representative or reaching out to our support team. We're here to help ensure a smooth experience for you.