In this article, we will learn how to get customers from Xero.
If you are looking for Xero integration please read this article.
The following elements are required in the Accounts response.
Code: Customer defined alphanumeric account code
Name: Name of account
BankAccountNumber: For bank accounts only (Account Type BANK)
Status: ACTIVE OR ARCHIVED
Description: Description of the Account
UpdatedDateUTC: Last modified date UTC format
The following elements are optional in the Accounts response.
AccountID : The Xero identifier for an account – specified as a string following the endpoint name e.g. 2f54f12f5-cc47-4afd-8ec8-74990b
C# Code Example
Create the Helpers folder and make a class file name XeroApiHelper.cs and add the code in it.
using System; using Xero.Api.Core; using Xero.Api.Example.Applications.Partner; using Xero.Api.Example.Applications.Public; using Xero.Api.Infrastructure.Interfaces; using Xero.Api.Infrastructure.OAuth; using Xero.Api.Example.TokenStores; using Xero.Api.Serialization; using System.Configuration; namespace XeroApplication.Helpers { public class ApplicationSettings { public string BaseApiUrl { get; set; } public Consumer Consumer { get; set; } public object Authenticator { get; set; } } public static class XeroApiHelper { private static ApplicationSettings _applicationSettings; static XeroApiHelper() { // Refer to README.md for details //var callbackUrl = ""; var callbackUrl = ConfigurationManager.AppSettings["callbackUrl"]; var memoryStore = new MemoryTokenStore(); var requestTokenStore = new MemoryTokenStore(); var baseApiUrl = ConfigurationManager.AppSettings["baseApiUrl"]; //var baseApiUrl = ""; // Consumer details for Application var consumerKey = ConfigurationManager.AppSettings["consumerKey"]; var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"]; // Signing certificate details for Partner Applications //var signingCertificatePath = @"C:\Dev\your_public_privatekey.pfx"; //var signingCertificatePassword = "Your_signing_cert_password - leave empty if you didn't set one when creating the cert"; // Public Application Settings var publicConsumer = new Consumer(consumerKey, consumerSecret); var publicAuthenticator = new PublicMvcAuthenticator(baseApiUrl, baseApiUrl, callbackUrl, memoryStore, publicConsumer, requestTokenStore); var publicApplicationSettings = new ApplicationSettings { BaseApiUrl = baseApiUrl, Consumer = publicConsumer, Authenticator = publicAuthenticator }; _applicationSettings = publicApplicationSettings; } public static ApiUser User() { return new ApiUser { Name = Environment.MachineName }; } public static IConsumer Consumer() { return _applicationSettings.Consumer; } public static IMvcAuthenticator MvcAuthenticator() { return (IMvcAuthenticator)_applicationSettings.Authenticator; } public static IXeroCoreApi CoreApi() { if (_applicationSettings.Authenticator is IAuthenticator) { return new XeroCoreApi(_applicationSettings.BaseApiUrl, _applicationSettings.Authenticator as IAuthenticator, _applicationSettings.Consumer, User(), new DefaultMapper(), new DefaultMapper()); } return null; } } }
Open the HomeController.cs file and create a new method and add the below code in it.
var api = XeroApiHelper.CoreApi(); List<Xero.Api.Core.Model.Account> GetAccounts =new List<Xero.Api.Core.Model.Account>(); GetAccounts = api.Accounts.Find().ToList();
You can explore API by the following URL