Introducing the .NET wrapper for the Sage One Accounting API

Pieter van der Westhuizen, a professional freelance web & mobile developer and founder of Coalition Software.
Search for a command to run...

Pieter van der Westhuizen, a professional freelance web & mobile developer and founder of Coalition Software.
A recent requirement came up for configurable dynamic forms in a mobile application. There are a few dynamic form packages for Flutter, but I wanted a bit more control over the schema and behavior of the form. Here follows my attempt at creating dyna...

If you've ever written a mobile app with Flutter that integrates with an API, then you'll know that there are a lot of model objects that get passed between the app and the API. JSON Serialization in Flutter can also take a fair amount of boilerplate...

Back in May 2020, Microsoft announced a new feature for Azure Blob Storage called Blob Index. Essentially, this enables you to add key/value tags to your Blob objects and be able to query said Blob objects without having to use a separate service lik...

In my last post, "Using AWS Cognito with Xamarin Forms", I showed how to authenticate with Amazon Cognito using Xamarin Forms and the Xamarin.Essentials Web Authenticator. In this post, we'll go through the process of using the AWS Cognito Hosted UI ...

In this post, I'll show you how to quickly and easily set up user authentication for your Xamarin Forms app using Amazon Cognito. AWS Cognito is a user identity management solution by Amazon. It is a really easy way to add authentication to your appl...

A while back my accountant convinced me to move our accounting package to Sage One Online. Not only am I very happy with the change, I’m also intrigued with their API, which enables developers to integrate with Sage One and perform a wide range of tasks . As a result I’ve created an open source project with the aim to create a fully fledged .Net wrapper library for the Sage One Accounting API. The code is available on GitHub, so please feel free to grab your fork and start contributing! The project is still under active development and I’m adding features as I need them. As of writing, the library supports the following operation s:
Account
Customer
Company
Item
Categories (Account, Asset, Bank Account, Customer, Item, Supplier)
Sales Representative
Supplier
Tax Invoice
For example to get a list of customers on Sage One you’ll use the following C# code:
public void GetAllCustomers()
{
var api = new ApiRequest(Username, Password, Apikey, CompanyId);
var customers = api.CustomerRequest.Get();
}
The Sage One API is pretty neat in the fact that it support OData queries out of the box. For example to find a customer with an e-mail address, you can simply pass in a filter parameter to the Get method:
public void GetCustomerByEmail()
{
string filter = "Email eq 'info@contoso.com'";
var api = new ApiRequest(Username, Password, Apikey, CompanyId);
var customers = api.CustomerRequest.Get(filter);
}
In case you’re wondering how OData queries work, take a look at the following example. The load a customer by ID, you’ll use the following:
public void GetCustomer()
{
int customerId = 12345;
var api = new ApiRequest(Username, Password, Apikey, CompanyId);
var customer = api.CustomerRequest.Get(customerId);
}
In order to create a new Sage One Customer, you’ll need to create a new instance of the Customer class, as illustrated below:
public void SaveCustomer()
{
var api = newApiRequest(Username, Password, Apikey, CompanyId);
var customer = new Customer
{
Name = "Mr. David R. Robinett",
AcceptsElectronicInvoices = true,
Active = true,
AutoAllocateToOldestInvoice = true,
Balance = 0,
ContactName = "Mr. David R. Robinett",
DeliveryAddress01 = "Pappelallee 6667",
DeliveryAddress02 = "Solingen",
DeliveryAddress03 = "Nordrhein-Westfalen",
DeliveryAddress04 = "42651",
DeliveryAddress05 = "Germany",
CommunicationMethod = 1,
PostalAddress01 = "Pappelallee 6667",
PostalAddress02 = "Solingen",
PostalAddress03 = "Nordrhein-Westfalen",
PostalAddress04 = "42651",
PostalAddress05 = "Germany",
Telephone = "238-555-0100",
SalesRepresentativeId = null
};
api.CustomerRequest.Save(customer);
}
To delete a Sage One Customer, simply call the Delete method:
public void Delete()
{
int customerId = 12345;
var api = new ApiRequest(Username, Password, Apikey, CompanyId);
var result = api.CustomerRequest.Delete(customerId);
}
To create a Tax Invoice:
public void CreateInvoice()
{
var api = new ApiRequest(Username, Password, Apikey, CompanyId);
var customerId = 0;
var salesRepId = 0;
var itemId = 0;
var taxTypeId = 0;
TaxInvoice invoice = new TaxInvoice();
var customer = api.CustomerRequest.Get(customerId);
var salesRep = api.SalesRepresentativeRequest.Get(salesRepId);
// Must set both CustomerId and Customer in order to work
invoice.CustomerId = customerId;
invoice.Customer = customer;
// Must set both SalesRepresentativeId and SalesRepresentative in order to work
invoice.SalesRepresentativeId = salesRepId;
invoice.SalesRepresentative = salesRep;
invoice.Date = DateTime.Now;
invoice.DueDate = new DateTime(2015, 12, 12);
invoice.Lines = new List<CommercialDocumentLine>();
var line1 = new CommercialDocumentLine
{
SelectionId = itemId, // This must be an item or account id
TaxTypeId = taxTypeId, // Use TaxTypeRequest to get list of Tax Types
LineType = 0, // 0=Item/1=Account
Quantity = 1,
UnitPriceExclusive = 390,
UnitPriceInclusive = 390,
DiscountPercentage = 0
};
invoice.Lines.Add(line1);
var newTaxInvoice = api.TaxInvoiceRequest.Save(invoice);
}
Lots more to come. Keep watching this space!