createAccount
Creates a new chart of accounts
/Accounts
Usage and SDK Samples
curl -X "https://api.xero.com/api.xro/2.0/Accounts"
import org.openapitools.client.api.*;
import org.openapitools.client.api.client.AccountingApi;
import org.openapitools.client.models.accounting.*;
import java.io.File;
import java.util.*;
public class AccountingApiExample {
private AccountingApi apiInstance;
public static void main(String[] args) {
String accessToken = "YOUR_ACCESS_TOKEN";
// Init AccountingApi client
ApiClient defaultClient = new ApiClient();
// Get Singleton - instance of accounting client
apiInstance = AccountingApi.getInstance(defaultClient);
String xeroTenantId = "YOUR_XERO_TENANT_ID";
Account account = new Account();
account.setCode("123456");
account.setName("FooBar");
account.setType(com.xero.models.accounting.AccountType.EXPENSE);
account.setDescription("Hello World");
try {
Accounts result = apiInstance.createAccount(accessToken, xeroTenantId, account);
System.out.println(result);
} catch (XeroException e) {
System.err.println("Exception when calling AccountingApi#createAccount");
e.printStackTrace();
}
}
}
import org.openapitools.client.api.AccountingApi;
public class AccountingApiExample {
public static void main(String[] args) {
AccountingApi apiInstance = new AccountingApi();
String xeroTenantId = YOUR_XERO_TENANT_ID; // String | Xero identifier for Tenant
Account account = { "Code":"123456", "Name":"Foobar", "Type":"EXPENSE", "Description":"Hello World" }; // Account |
try {
Accounts result = apiInstance.createAccount(xeroTenantId, account);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AccountingApi#createAccount");
e.printStackTrace();
}
}
}
Configuration *apiConfig = [Configuration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: OAuth2)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
String *xeroTenantId = YOUR_XERO_TENANT_ID; // Xero identifier for Tenant (default to null)
Account *account = { "Code":"123456", "Name":"Foobar", "Type":"EXPENSE", "Description":"Hello World" }; //
AccountingApi *apiInstance = [[AccountingApi alloc] init];
// Creates a new chart of accounts
[apiInstance createAccountWith:xeroTenantId
account:account
completionHandler: ^(Accounts output, NSError* error) {
if (output) {
NSLog(@"%@", output);
}
if (error) {
NSLog(@"Error: %@", error);
}
}];
const tokenSet: TokenSet = {
id_token: 'xxx',
access_token: 'yyy',
expires_at: 1582308862,
token_type: 'Bearer',
refresh_token: 'zzz',
session_state: 'xxx'
}
await xero.setTokenSet(tokenSet);
const xeroTenantId = "YOUR_XERO_TENANT_ID"; // {String} Xero identifier for Tenant
const account: Account = { code: "123456", name: "Foobar", type: AccountType.EXPENSE, description: "Hello World" }
try {
const response = await xero.accountingApi.createAccount(xeroTenantId, account);
console.log(response.body || response.response.statusCode)
} catch (err) {
const error = JSON.stringify(err.response.body, null, 2)
console.log(`Status Code: ${err.response.statusCode} => ${error}`);
}
using System;
using System.Diagnostics;
using .Api;
using .Client;
using .Model;
namespace Example
{
public class createAccountExample
{
public void main()
{
// Configure OAuth2 access token for authorization: OAuth2
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new AccountingApi();
var xeroTenantId = YOUR_XERO_TENANT_ID; // String | Xero identifier for Tenant (default to null)
var account = new Account(); // Account |
try
{
// Creates a new chart of accounts
Accounts result = apiInstance.createAccount(xeroTenantId, account);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling AccountingApi.createAccount: " + e.Message );
}
}
}
}
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure OAuth2 access token for authorization: OAuth2
$config = XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()->setAccessToken( 'YOUR_ACCESS_TOKEN' );
$apiInstance = new XeroAPI\XeroPHP\Api\AccountingApi(
new GuzzleHttp\Client(),
$config
);
$xeroTenantId = "YOUR_XERO_TENANT_ID";
$account = new XeroAPI\XeroPHP\Models\Accounting\Account;
$account->setCode('123456');
$account->setName('FooBar');
$account->setType(XeroAPI\XeroPHP\Models\Accounting\AccountType::EXPENSE);
$account->setDescription('Hello World');
try {
$result = $apiInstance->createAccount($xeroTenantId, $account);
} catch (Exception $e) {
echo 'Exception when calling AccountingApi->createAccount: ', $e->getMessage(), PHP_EOL;
}
?>
use Data::Dumper;
use ::Configuration;
use ::AccountingApi;
# Configure OAuth2 access token for authorization: OAuth2
$::Configuration::access_token = 'YOUR_ACCESS_TOKEN';
my $api_instance = ::AccountingApi->new();
my $xeroTenantId = YOUR_XERO_TENANT_ID; # String | Xero identifier for Tenant
my $account = ::Object::Account->new(); # Account |
eval {
my $result = $api_instance->createAccount(xeroTenantId => $xeroTenantId, account => $account);
print Dumper($result);
};
if ($@) {
warn "Exception when calling AccountingApi->createAccount: $@\n";
}
# configure api_client for use with xero-python sdk client
api_client = ApiClient(
Configuration(
debug=false,
oauth2_token=OAuth2Token(
client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET"
),
),
pool_threads=1,
)
api_client.set_oauth2_token("YOUR_ACCESS_TOKEN")
def accounting_create_account():
api_instance = AccountingApi(api_client)
xeroTenantId = 'YOUR_XERO_TENANT_ID'
account = Account(
code = "123456",
name = "FooBar",
type = AccountType.EXPENSE,
description = "Hello World")
try:
api_response = api_instance.create_account(xeroTenantId, account)
print(api_response)
except AccountingBadRequestException as e:
print("Exception when calling AccountingApi->createAccount: %s\n" % e)
extern crate AccountingApi;
pub fn main() {
let xeroTenantId = YOUR_XERO_TENANT_ID; // String
let account = { "Code":"123456", "Name":"Foobar", "Type":"EXPENSE", "Description":"Hello World" }; // Account
let mut context = AccountingApi::Context::default();
let result = client.createAccount(xeroTenantId, account, &context).wait();
println!("{:?}", result);
}
Scopes
accounting.settings | Grant read-write access to organisation and account settings |
Parameters
Name | Description |
---|---|
xero-tenant-id* |
String
Xero identifier for Tenant
Required
|
Name | Description |
---|---|
account * |
Account
Account object in body of request
Required
|