Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Node.js Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(Node.js) Xero Create New Accounts

Demonstrates how to create a new account in Xero.

Note: Requires Chilkat v9.5.0.64 or greater.

Install Chilkat for Node.js and Electron using npm at

Chilkat npm packages for Node.js

Chilkat npm packages for Electron

on Windows, Linux, MacOSX, and ARM

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node11-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node11-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node11-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node11-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node11-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node11-macosx');
}

function chilkatExample() {

    // Note: Requires Chilkat v9.5.0.64 or greater.

    // This requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var rest = new chilkat.Rest();
    var success;

    // Before sending REST API calls, the REST object needs to be
    // initialized for OAuth1.
    // See Xero 2-Legged OAuth1 Setup for sample code.

    // Assuming the REST object's OAuth1 authenticator is setup, and the initial
    // connection was made, we may now send REST HTTP requests..

    // --------------------------------------------------------------
    // To add certain accounts, we need a unique Code that hasn't yet been used.
    // Chilkat provided an example to download and save the Accounts data.
    // We can load this data into a hashtable to help us find an unused Code.
    // See Hash Xero Account Codes to see how this file was created.
    var sbAccounts = new chilkat.StringBuilder();
    success = sbAccounts.LoadFile("qa_cache/xero_accounts_by_code.xml","utf-8");
    if (!success) {
        console.log("failed to load xero_accounts_by_code.xml");
        return;
    }

    var htAccounts = new chilkat.Hashtable();
    htAccounts.AddFromXmlSb(sbAccounts);

    // --------------------------------------------------------------
    // Build the request XML to create a Xero sales account.
    // Find an unused Code...
    var code = 600;
    while (htAccounts.ContainsIntKey(code) == true) {
        code = code+1;
    }

    var xml = new chilkat.Xml();
    xml.Tag = "Account";
    xml.NewChildInt2("Code",code);
    xml.NewChild2("Name","Sales - clearance lines");
    xml.NewChild2("Type","SALES");
    xml.EmitCompact = true;

    // Do not emit the XML declarator. Xero does not accept the XML if it
    // has the initial line: <?xml version="1.0" encoding="utf-8"?>
    xml.EmitXmlDecl = false;

    rest.AddQueryParam("xml",xml.GetXml());

    rest.VerboseLogging = true;
    var responseXml = rest.FullRequestFormUrlEncoded("PUT","/api.xro/2.0/Accounts");
    if (rest.LastMethodSuccess !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    // A 200 response is expected for actual success.
    if (rest.ResponseStatusCode !== 200) {
        console.log(responseXml);
        return;
    }

    // Examine the XML response
    console.log(responseXml);

    // A successful XML response is as follows:

    // <Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    //   <Id>dac71f1b-7afb-49a7-8a57-719b91f2088e</Id>
    //   <Status>OK</Status>
    //   <ProviderName>ChilkatPrivate</ProviderName>
    //   <DateTimeUTC>2016-11-10T23:53:43.487791Z</DateTimeUTC>
    //   <Accounts>
    //     <Account>
    //       <AccountID>cb8c94cf-57d4-41ee-b866-4c27632fe838</AccountID>
    //       <Code>601</Code>
    //       <Name>Sales - clearance lines</Name>
    //       <Status>ACTIVE</Status>
    //       <Type>SALES</Type>
    //       <TaxType>OUTPUT</TaxType>
    //       <Class>REVENUE</Class>
    //       <EnablePaymentsToAccount>false</EnablePaymentsToAccount>
    //       <ShowInExpenseClaims>false</ShowInExpenseClaims>
    //       <ReportingCode>REV</ReportingCode>
    //       <ReportingCodeName>Revenue</ReportingCodeName>
    //       <UpdatedDateUTC>2016-11-10T23:53:43.94</UpdatedDateUTC>
    //     </Account>
    //   </Accounts>
    // </Response>

    // To access the information:
    xml.LoadXml(responseXml);

    console.log("AccountID: " + xml.GetChildContent("Accounts|Account|AccountID"));
    console.log("TaxType: " + xml.GetChildContent("Accounts|Account|TaxType"));
    // ..

}

chilkatExample();

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.