-
Notifications
You must be signed in to change notification settings - Fork 0
Accounts
Eze Rodriguez edited this page Mar 14, 2020
·
2 revisions
accounts, err := xeroClient.Accounts.List(ctx, nil)
if err != nil {
fmt.Println(fmt.Errorf("error getting accounts: %v", err))
}
To order account results you might use the same List
method but passing a
struct of type AccountListOptions
as the second parameter specifying those fields that will be included as query
parameters part of the request URL
e.g:
opts := xero.AccountListOptions {
Order: "", // e.g "Name DESC"
}
orderedAccounts, err := xeroClient.Accounts.List(ctx, &opts)
...
This will always return a list of 0
or more Accounts
You can use the GetByID
method to get a single Account
.
e.g:
accountID := "00000000-0000-0000-0000-000000000000"
account, err := xeroClient.Accounts.GetByID(ctx, accountID)
if err != nil {
fmt.Println(fmt.Errorf("error: %v", err))
return
}
fmt.Printf("%+v\n", account)
account := &xero.Account{
Code: "12315",
Name: "Some account",
Type: xero.AccountTypeCurrentAsset,
}
a, err := xeroClient.Accounts.Create(ctx, account)
if err != nil {
fmt.Println(fmt.Errorf("error: %v", err))
return
}
// Existing Account
account := &xero.Account{
AccountID: "00000000-0000-0000-0000-000000000000",
Code: "12315",
Name: "Some account",
Type: xero.AccountTypeCurrentAsset,
}
// Update one field of the account
account.Name = "New name"
a, err := client.Accounts.Update(ctx, account)
if err != nil {
return nil, err
}
fmt.Printf("New Account name: %s\n", a.Name)