Sage One API .NET Wrapper

A C# wrapper library for the Sage One Accounting API

View project on GitHub

.NET wrapper for the Sage One Accounting API

A .Net client library for using the Sage One Accounting API. Read more about the API at: https://accounting.sageone.co.za/Marketing/DeveloperProgram.aspx

This project is under active development. If you wish to contribute, please follow the existing coding conventions and submit a pull request. For more information and usage examples visit http://www.mythicalmanmoth.com/2015/09/08/net-wrapper-sage-one-accounting-api/

Currently, the following objects/methods are available in the library:

GetAll Get Save Delete Get w/System Accounts Get By Category Get Current Has Activity Calculate Email
Account :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Account Category :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Account Note :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Account Receipt :heavy_check_mark: :heavy_check_mark:
Additional Price List :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Additional Item Price :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Asset :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Asset Category :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Asset Locations :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Asset Notes :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Bank Account :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Bank Account Category :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Customer :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Customer Category :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Customer Notes :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Company :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Item :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Item Movement :heavy_check_mark:
Item Notes :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Item Category :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Journal Entry :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Purchase Order :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Sales Representative :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Supplier :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Supplier Category :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Supplier Invoice :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Tax Invoice :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Tax Type :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:

If you need to create test data for your developer account, take a look at the tests inside SampleDataCreate.cs

Code Examples

Get a list of Sage One Customers:
public void GetAllCustomers()
{
    var api = new ApiRequest(Username, Password, Apikey, CompanyId);
    var customers = api.CustomerRequest.Get();
}
Get a Sage One Customer with specific email address (OData query):
public void GetCustomerByEmail()
{
    string filter = "Email eq 'info@contoso.com'";
    var api = new ApiRequest(Username, Password, Apikey, CompanyId);
    var customers = api.CustomerRequest.Get(filter);
}
Get a Sage One Customer by id:
public void GetCustomer()
{
    int customerId = 12345;
    var api = new ApiRequest(Username, Password, Apikey, CompanyId);
    var customer = api.CustomerRequest.Get(customerId);
}   
Create a new Sage One Customer:
public void SaveCustomer()
{
    var api = new ApiRequest(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);
}
Delete a new Sage One Customer:
public void Delete()
{
    int customerId = 12345;
    var api = new ApiRequest(Username, Password, Apikey, CompanyId);
    var result = api.CustomerRequest.Delete(customerId);
}
Create Sage One 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(2016, 01, 01);

    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);
}   

This project borrowed heavily from the concepts used by Scott Schluer and his .Net Wrapper for the Highrise Api