Sage 50 .NET API - Quick Start Guide
Sage 50 .NET API - Quick Start Guide
Edition
Software development kit
.NET API quick start guide
Table of contents
Deprecations ....................................................................................................................................... 4
Overview ...................................................................................................................................................... 6
Visual C# ............................................................................................................................................... 12
Overview ................................................................................................................................................ 14
Silver membership................................................................................................................................ 14
Page 2
Troubleshooting .................................................................................................................................... 15
Page 3
Changes in version 2018.0
Note: In Release 2016 the .NET SDK was moved to .NET 4.5.2 and was built with Visual Studio
2012. You may need to update your application to use .NET 4.5.2 in order to be able to call the
.NET SDK.
Deprecations
<none>
Page 4
o Unit of Measure—the SDK cannot be used to edit or delete transactions involving
Units of Measure.
o Cross-Payments—the SDK cannot be used to edit or delete Receipts from a
Vendor or Payments to a customer.
o Sales Invoices against Proposals—the SDK cannot be used to edit or delete
Sales Invoices that apply against a proposal.
o Audit Trail entries are not generated for sales invoices generated through the
SDK.
Page 5
Overview
Thank you for your interest in the Sage 50 Third Party Add-on Program. The Sage 50 Software
Development Kit (SDK) exposes some of the new features in Sage 50 Accounting. This
document is intended to be a Quick Start Guide for Third-Party developers interested in
connecting their application with Sage 50 through the .NET API. The Sage 50 SDK includes
many sample applications that expand on this Quick Start Guide. There is also a Sage 50 .NET
API help file installed with the Sage 50 .NET SDK that explains each class property and method
available.
The main focus of the Sage 50 .NET API is to allow for client applications to connect and
activate methods without the need to launch the Sage 50 application. The .NET API offers a
more object-oriented approach of interfacing with Sage 50. The .NET API makes use of
Generics and LINQ expressions introduced in .NET Framework 2.0. The .NET API is available
with Sage 50 versions 2011 and later.
The third-party application is allowed to connect to Sage 50 Accounting without the need for
Sage 50 to be launched. The third-party application will create an instance of the
PeachtreeSession object that calls a Begin method which takes an application ID as its String
parameter. Each third-party application will be associated with a unique application ID provided
by Sage. For developers who wish to test only with the sample companies installed with Sage
50 Accounting, an application ID is not necessary and may be passed as an empty String
parameter in the Begin method of the PeachtreeSession object.
Page 6
Getting started
After you install Sage 50, make sure you reboot your machine in order to get your app to build
and work properly. As well, in order to use the .NET API, you need a reference in your Visual
Studio project to the Sage.Peachtree.API assembly, which is in the install folder of Sage 50 and
registered in the Global Assembly Cache (GAC) of Microsoft Windows. To start using the .NET
API with a nonsample company, a valid application ID is needed. You should have received
your application ID in an email after you downloaded the SDK. If not, or if you have questions
about your application ID, send an email to [email protected] for assistance. If you use a
blank application ID, you will only be able to connect to Sage 50 sample companies.
For the 2018.0 release of Sage 50, a variety of sample applications is provided in the Sage 50
SDK download package. Many of the sample applications extend the documentation to
demonstrate areas beyond the scope of the SDK documentation. The SDK includes sample
applications and documentation that was written for Visual Studio 2012. Many of the samples
packaged with the Sage 50 SDK and code references in this document make use of Microsoft
Visual Studio. The Visual Studio Express IDE can be downloaded at
http://www.microsoft.com/express/Windows to evaluate the samples provided.
Page 7
Programming languages
Adding a reference
For the 2018.0 release, the Sage 50 .NET API assembly is distributed as part of the Sage 50
Accounting 2018.0 installation. It is also registered in the Global Assembly Cache (GAC). The
.NET API is tightly linked to the application and allows existing applications to function with
minor changes. In order to use the .NET API, you will need to add a reference to the
Sage.Peachtree.API assembly in your Visual Studio project:
To add a reference to the .NET API in your existing .NET client code, do the following:
Note: You can also reference the .NET API by manually browsing to the Sage.Peachtree.API.dll
file in the API folder inside the install folder of Sage 50:
Page 8
Adding the namespace
The namespace of the .NET API is “Sage.Peachtree.API” and should be added to the .NET
client application code.
Sample code
Visual C#
using Sage.Peachtree.API;
Visual Basic
Imports Sage.Peachtree.API
Page 9
Initial connection
The PeachtreeSession class is the entry point of the Sage 50 .NET API. You must create a
PeachtreeSession object must be created. The Begin method must be called passing in either a
blank or valid application ID as a String parameter. If you enter a blank application ID, you will
only be able to connect to Sage 50 sample companies. A valid application ID is needed in order
to connect to regular Sage 50 companies (nonsample companies). To have a unique application
ID generated for your third-party application, please send a request to [email protected].
Sample code
Visual C#
Visual basic
Page 10
Request access to company
After the third-party application has begun a session with the Sage 50 program, it must first
request access to the company it will open. To do this, the third-party application will call the
RequestAccess method, which returns an enumerated value representing the state of the
request. The request can be one of the following states:
Sample code
Visual C#
// Request authorization from Sage 50 for our third-party application to access company.
AuthorizationResult AuthResult = apiSession.RequestAccess(companyId);
Visual Basic
' Request authorization from Sage 50 for our third-party application to access company.
Dim authorizationResult As AuthorizationResult = apiSession.RequestAccess(companyId)
Page 11
Open company
The following sample code demonstrates how to open a Sage 50 company using the .NET API.
The third-party application will use the Open method of the PeachtreeSession class to access a
company. The Open method returns a context to a Company class object which provides the
primary connection point for a Sage 50 company.
Sample code
Visual C#
Page 12
Visual basic
Page 13
Sage 50 development partner program
Overview
Participation in the Development partner program can increase your exposure to the vibrant
small and midsized applications market. If you have an application that adds functional value to
Sage 50, we encourage you to apply for Silver or Gold level program membership.
Gold membership
An invitation to participate at our annual partner conference. Booth and sponsorship
opportunity charges are separate from program fees and are outlined closer to the
conference date.
Marketing exposure on: www.sagepss.com
Access to not-for-resale software to test your product integration
Access to the Gold Development Partner Logo
A Sage 50 SDK-specific support plan (five incidents)
View full program requirements and benefits
Silver membership
An invitation to participate at our annual partner conference. Booth and sponsorship
opportunity charges are separate from program fees and are outlined closer to the
conference date.
Marketing exposure on: www.sagepss.com
Access to not-for-resale software to test your product integration
Access to the Silver Development Partner Logo
A Sage 50 SDK-specific support plan (one incident)
View full program requirements and benefits
Page 14
Sage 50 SDK community
In addition to the documentation and sample code provided in the Sage 50 SDK package,
developers have access to the Sage 50 SDK Community where they can discuss the SDK with
other developers using the Sage 50 SDK. Visit Sage City to set up your account.
Troubleshooting
1. If you get the following error message when you run your application:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0"/>
<supportedRuntime version="v4.0"/>
</startup
Page 15