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";
+ ApiClient defaultClient = new ApiClient();
+
+ 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);
+ }
+ }];
+
+ await xero.setTokenSet(tokenSet);
+
+const xeroTenantId = 'YOUR_XERO_TENANT_ID';
+
+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 Xero.NetStandard.OAuth2.Api;
+using Xero.NetStandard.OAuth2.Client;
+using Xero.NetStandard.OAuth2.Model;
+
+namespace Example
+{
+ public class CreateAccountExample
+ {
+ public async Task Main()
+ {
+ var accessToken = "YOUR_ACCESS_TOKEN";
+ var apiInstance = new AccountingApi();
+ var xeroTenantId = "YOUR_XERO_TENANT_ID";
+
+ var account = new Account();
+ account.Code = "123456";
+ account.Name = "FooBar";
+ account.Type = AccountType.EXPENSE;
+ account.Description = "Hello World";
+
+ try {
+ var result = await apiInstance.CreateAccountAsync(accessToken, xeroTenantId, account);
+ Console.WriteLine(result);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Exception when calling apiInstance.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)
+ xero_tenant_id = 'YOUR_XERO_TENANT_ID'
+
+ account = Account(
+ code = "123456",
+ name = "FooBar",
+ type = AccountType.EXPENSE,
+ description = "Hello World")
+
+ try:
+ api_response = api_instance.create_account(xero_tenant_id, account)
+ print(api_response)
+ except AccountingBadRequestException as e:
+ print("Exception when calling AccountingApi->createAccount: %s\n" % e)
+ xero_client.set_token_set(user.token_set)
+
+xero_tenant_id = 'YOUR_XERO_TENANT_ID'
+
+account = {
+ code: "123456",
+ name: "FooBar",
+ type: XeroRuby::Accounting::AccountType::EXPENSE,
+ description: "Hello World"
+}
+
+begin
+ response = xero_client.accounting_api.create_account(xero_tenant_id, account)
+ return response
+rescue XeroRuby::ApiError => e
+ puts "Exception when calling create_account: #{e}"
+end
+
+ 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
+
+ |
+