Introducing the .NET wrapper for the Sage One Accounting API

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 operations:

  • Account
    • Get All
    • Get
    • Save (Create and Update)
    • Delete
    • Get with System Accounts
    • Get by Category
  • Customer
    • Get All
    • Get
    • Save (Create and Update)
    • Delete
  • Company
    • Get Current
  • Item
    • Get All
    • Get
    • Save (Create and Update)
    • Delete
  • Categories (Account, Asset, Bank Account, Customer, Item, Supplier)
    • Get All
    • Get
    • Save (Create and Update) excl. Account Categories
    • Delete
  • Sales Representative
    • Get All
    • Get
    • Save (Create and Update)
    • Delete
    • HasActivity
  • Supplier
    • Get All
    • Get
    • Save (Create and Update)
    • Delete
  • Tax Invoice
    • Get All
    • Get
    • Save (Create and Update)
    • Calculate

For example to get a list of customers on Sage One you’ll use the following C# code:

Get list of Sage One Customers
  1. public void GetAllCustomers()
  2. {
  3.     var api = new ApiRequest(Username, Password, Apikey, CompanyId);
  4.     var customers = api.CustomerRequest.Get();
  5. }

 

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:

Filter Sage One Customers
  1. public void GetCustomerByEmail()
  2. {
  3.     string filter = “Email eq ‘info@contoso.com'”;
  4.     var api = new ApiRequest(Username, Password, Apikey, CompanyId);
  5.     var customers = api.CustomerRequest.Get(filter);
  6. }

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:

Get Sage One Customer by ID
  1. public void GetCustomer()
  2. {
  3.     int customerId = 12345;
  4.     var api = new ApiRequest(Username, Password, Apikey, CompanyId);
  5.     var customer = api.CustomerRequest.Get(customerId);
  6. }

 

In order to create a new Sage One Customer, you’ll need to create a new instance of the Customer class, as illustrated below:

Create a new Sage One Customer
  1. public void SaveCustomer()
  2. {
  3.     var api = new ApiRequest(Username, Password, Apikey, CompanyId);
  4.     var customer = new Customer
  5.     {
  6.         Name = “Mr. David R. Robinett”,
  7.         AcceptsElectronicInvoices = true,
  8.         Active = true,
  9.         AutoAllocateToOldestInvoice = true,
  10.         Balance = 0,
  11.         ContactName = “Mr. David R. Robinett”,
  12.         DeliveryAddress01 = “Pappelallee 6667”,
  13.         DeliveryAddress02 = “Solingen”,
  14.         DeliveryAddress03 = “Nordrhein-Westfalen”,
  15.         DeliveryAddress04 = “42651”,
  16.         DeliveryAddress05 = “Germany”,
  17.         CommunicationMethod = 1,
  18.         PostalAddress01 = “Pappelallee 6667”,
  19.         PostalAddress02 = “Solingen”,
  20.         PostalAddress03 = “Nordrhein-Westfalen”,
  21.         PostalAddress04 = “42651”,
  22.         PostalAddress05 = “Germany”,
  23.         Telephone = “238-555-0100”,
  24.         SalesRepresentativeId = null
  25.     };
  26.     api.CustomerRequest.Save(customer);
  27. }

 

To delete a Sage One Customer, simply call the Delete method:

Delete a Sage One Customer
  1. public void Delete()
  2. {
  3.     int customerId = 12345;
  4.     var api = new ApiRequest(Username, Password, Apikey, CompanyId);
  5.     var result = api.CustomerRequest.Delete(customerId);
  6. }

 

To create a Tax Invoice:

Create Sage One Tax Invoice
  1. public void CreateInvoice()
  2. {
  3.     var api = new ApiRequest(Username, Password, Apikey, CompanyId);
  4.     var customerId = 0;
  5.     var salesRepId = 0;
  6.  
  7.     var itemId = 0;
  8.     var taxTypeId = 0;
  9.  
  10.     TaxInvoice invoice = new TaxInvoice();
  11.     var customer = api.CustomerRequest.Get(customerId);
  12.     var salesRep = api.SalesRepresentativeRequest.Get(salesRepId);
  13.  
  14.     // Must set both CustomerId and Customer in order to work
  15.     invoice.CustomerId = customerId;
  16.     invoice.Customer = customer;
  17.  
  18.     // Must set both SalesRepresentativeId and SalesRepresentative in order to work
  19.     invoice.SalesRepresentativeId = salesRepId;
  20.     invoice.SalesRepresentative = salesRep;
  21.  
  22.     invoice.Date = DateTime.Now;
  23.     invoice.DueDate = new DateTime(2015, 12, 12);
  24.  
  25.     invoice.Lines = new List<CommercialDocumentLine>();
  26.  
  27.     var line1 = new CommercialDocumentLine
  28.     {
  29.         SelectionId = itemId, // This must be an item or account id
  30.         TaxTypeId = taxTypeId, // Use TaxTypeRequest to get list of Tax Types
  31.         LineType = 0, // 0=Item/1=Account
  32.         Quantity = 1,
  33.         UnitPriceExclusive = 390,
  34.         UnitPriceInclusive = 390,
  35.         DiscountPercentage = 0
  36.     };
  37.  
  38.     invoice.Lines.Add(line1);
  39.  
  40.     var newTaxInvoice = api.TaxInvoiceRequest.Save(invoice);
  41. }

Lots more to come. Keep watching this space!

Need help with you next ASP.Net MVC Project?

Do you need guidance with your next .Net project?Contact me for ASP.Net MVC and .Net software development and consulting.

Create South African test data with NBuilder and Faker

I’ve recently read an excellent article by Jerrie Pelser about using NBuilder and Faker.Net to generate test data for your .Net project – something I actually need on a regular basis.

However, I needed data that looked a bit more South African so, I’ve added some South African flavour to Faker.Net. You can now generate South African names, surnames, provinces and actual valid ID numbers for use as test data in your project.

In the following example I generate 100 client records with random South African names, surnames, provinces and ID numbers:

Code Snippet
  1. protected override void Seed(ApplicationDbContext context)
  2. {
  3.     var customers = Builder<Client>.CreateListOfSize(100)
  4.         .All()
  5.             .With(c => c.Firstname = Faker.SouthAfrican.Firstname())
  6.             .With(c => c.Lastname = Faker.SouthAfrican.Lastname())
  7.             .With(c => c.Province = Faker.SouthAfrican.Province())
  8.             .With(c => c.IdNumber = Faker.SouthAfrican.IdNumber())
  9.         .Build();
  10.     context.Clients.AddOrUpdate(c => c.Id, customers.ToArray());
  11. }

You can get the code on Github.

Resources used for this article:

Office 365 API – Authentication & Setup

In our last article, we took a 10,000 foot view of what Office 365 has to offer. The article also made note of the Office 365 API, which enables developers to integrate with and use their users’ Office 365 data.

Before we can access the users’ data, we’ll need to authenticate our Office app and make sure it has the required permissions to access said data. This is accomplished by using single sign-on with Azure AD. The Office 365/Azure AD authentication uses OpenID Connect and OAuth 2.0, which is an open standard and if you’ve ever authenticated using either Facebook, Twitter or a Google account, the process of authenticating with Azure AD will be very familiar to you.

For the purpose of this article, we’ll only focus on authenticating using the new Office 365 Unified API. Although it is still only in preview, it will very shortly become the de facto method to access Office 365 data.

Read more at Add-in Express.

To see all my recent Add-in Express blog posts visit my author page.

Office 365 for developers – What, How, Where?

With Build and Ignite behind us we’ve seen some pretty incredible things from Microsoft, from mobile to virtual reality. If you haven’t watched the Build keynote or some of the sessions yet, I encourage you to do so.

Office 365 for the future

These are very exciting times, especially for MS Office developers. Satya Nadella, CEO of Microsoft, confirmed that “The most strategic developer surface area for us is Office 365“.

This means that the Office 365 platform is one of the most important areas for Microsoft as part of their vision for the future. It’s also an indication that Microsoft feels that developers need to embrace Office 365 in order for it to be an even bigger success.

Read more at Add-in Express.

To see all my recent Add-in Express blog posts visit my author page.

Graphics formats for Microsoft Office add-ins

Chances are that in the majority of Microsoft Office add-ins, you’ll be using at least one ribbon or command bar button. I do not know about you, but I can sometimes get hung up about which icon to use and deciding on which image will convey more accurately the task that will be performed once the user clicks on said ribbon or command bar button.

In today’s article, we’ll explore the various graphic formats supported by MS Office components and how to make them appear the best they can be.

Read more at Add-in Express.

To see all my recent Add-in Express blog posts visit my author page.

.

Windows and Office security guide for Office developers

Office add-in security and certificates has always been somewhat of a daunting task. In today’s article we’ll first investigate code-signing certificates and why they are used. We’ll then take a closer look at the Office Trust Center function and settings.

Read more at Add-in Express.

To see all my recent Add-in Express blog posts visit my author page.

Bootstrap for ASP.NET MVC Q&A

Thank you to everyone who bought my book Bootstrap for ASP.NET MVC!

If you have any questions about the content in the book or have any questions regarding ASP.Net MVC and Bootstrap, please feel free to use the comments on this blog post to ask it.

 

How to determine when a user has read an Outlook message

In today’s article we’ll look at how to determine when a user has read an Outlook mail message. There are a variety of ways a message can be marked as read, e.g.:

  • The user right-clicked the message in the Explorer and selected the “Mark as Read” context-menu item; or
  • The mail message was opened in an inspector window, usually by double-clicking the message in the Outlook Explorer; or
  • Viewing the message in the Outlook reading pane.

We’ll create an Outlook add-in that illustrates the various methods of responding to the the fact that a user has read an e-mail in Outlook.

Read more at Add-in Express.

To see all my recent Add-in Express blog posts visit my author page.

Working with Outlook HTMLBody – a guide for Office developers

If you’ve ever tried to design an attractive and somewhat complex e-mail message using Microsoft Outlook and HTML, chances are you very quickly realized that the Outlook mail message body format performs rather differently than a normal web browser.

<p align="justify">Read more at <a href="https://www.add-in-express.com/creating-addins-blog/2015/02/23/outlook-htmlbody-guide/">Add-in Express</a>.</p>

<blockquote>
  <p align="justify">To see all my recent Add-in Express blog posts visit my <a href="http://www.add-in-express.com/creating-addins-blog/author/pieter-van-der-westhuizen/">author page.</a></p>
</blockquote>

How to implement auto-update for Office add-ins

Automatic updates for software applications’ mobile apps have become an everyday occurrence for most users. For a user it provides a level of comfort to know that their software is always up to date with the latest and greatest version. It could also be a source of irritation for many users depending on the frequency of updates – not many users would be happy upgrading to a new version every day.

Of course, Office Add-in is no exception and it is also necessary to deploy a new version of your add-in from time to time.

Read more at Add-in Express.

To see all my recent Add-in Express blog posts visit my author page.