Category Archives: Integrations

Integration topics that define how to transfer data from one system to another.

How to consume an OAuth based REST service

Recently I decided to dive deep into REST services because of how prominent they are becoming in the industry.  Nearly most of my coding time is spent figuring out how to take one piece of software or code and connect it with another piece of software or code to produce the expected result.  RESTful web services are a great way to take a generic design such as Json or XML and come up with a standard library to talk to any system.  If you aren’t familiar with REST services, they are a simple form of HTTP communication that takes basic HTTP commands: GET, PUSH, PUT and DELETE and translates them into CRUD operations.

What does this all mean?  It means that you can call a website through a standard website client and treat it just as if you were hitting a data source.  Pretty neat huh?  A large chunk of the REST services out on the market now deal in Json with support for XML.  Json is a nice language that allows for dynamic object design without having any formal definition.  If you want to add a field, you add it.  It is very extensible and light weight allowing for quick and scalable data operations.

So how does OAuth play into all of this?  OAuth is a system that allows you to connect your application to another application in a secure fashion.  To start out, you give your application an ID.  This is sent to a service in the form of a request for access, and the user who is using your application grants what access they want to give.  Once granted your application gets back an authorization key which it uses to make future calls.  The beauty of this system is it puts the security and functionality of the application in the hands of the user and the end service.  All you need to worry about is what your authorization key is and how what services you should be calling at a given time.

My goto library for this type of call currently is called RestSharp.  This library is a REST service library built out for everything we are doing here.   Here is an example of how to create a client and make a call:

Dim auth = New RestClient(SiteURL)
Dim rqst As New RestRequest("wc-api/v2/orders", Method.GET)
Dim rtn As RestResponse

rqst.RequestFormat = DataFormat.Json
auth.Authenticator = New HttpBasicAuthenticator(ConsumerKey, ConsumerSecret)
rtn = auth.Execute(rqst)

With this call, you are reaching out to a popular WordPress plugin called WooCommerce to get a list of orders and returning back the HTTP response.  This response will be in a Json string that you can parse using the popular Newtonsoft library.  The request has all of the standard CRUD operations as well as numerous authentication libraries on top of OAuth.  For more details information about REST services or OAuth, check out the standards page here on W3C.

Exchange Web Services Notifications

Something that I have always enjoyed working with is the exchange web services notifications engine.  This process not only allows you to jump in and fetch information from exchange through the exchange web services but it also gives you a nice subscriber model for responding to any exchange events.  This includes things like emails being received in a specified folder, or calendar entry changes, etc.  What I would like to show you is a quick overview of how the exchange notifications can be grabbed and utilized for whatever you so desire.  In my specific example I am grabbing email notifications and handling them with some business logic to assign them to cases in a help desk system.

Exchange Web Services Notifications – Fetching an event

Our first step is to create an exchange web service object that holds the URL to our service:

Dim excExchangeService As New ExchangeService(ExchangeVersion.Exchange2010)
excExchangeService = New ExchangeService(ExchangeVersion.Exchange2010)
excExchangeService.Url = New Uri(_mExchangeURL)

At this point we subscribe to the event that we awant to grab, and run a loop to hit it until we have events:

While True
    gerResult = plsSubscription.GetEvents()
    For Each ntfEvent As NotificationEvent In gerResult.AllEvents
      If TypeOf ntfEvent Is ItemEvent Then
        ..Handle notification event
      End If
  Loop While plsSubscription.MoreEventsAvailable
End While

Exchange Web Services Notifications – What do I do with an item once I have it?

Each event will be typed as either an item type specific to the folder or location that you setup your pull to pull from. In my specific example I setup a few timers to listen to email boxes and waited for the events to come in. When they come in I get an email item so I call the EmailMessage.Bind method to bind an Email object and read some information about the email.

A big push in .NET and software development in general is to move away from a service based process that reads every 5 minutes and sends updates and move into more of a reactionary event driven approach.  This is the best of both worlds, as you do not have to have an event driven model but at the same time your timer is not reading every certain time period and pulling in information.  By providing a real-time system that reacts to events we can tightly integrate our applications with the exchange processes.

Exchange Web Services Notifications provides not only a place for you to hook into great events from the exchange process, but an excellent object model for retrieving any information you need about exchange.

How to find your GP Company ID

Often times when working with Dynamics GP you will come across something that is asking for a GP company ID.  This can either be an integration application, or a registration program for a cool addin, or a number of other pieces that need to connect to your data.  GP has three ways to identify a company: Company Name, Database Name and Company ID.  All of these luckily can be found in one table in a database.  By selecting out of the SY01500 table we can determine how to find your GP company ID.  Here is an example query:

How to find your GP Company ID


how to find your gp company id

This will return back the Company Name as CMPNYNAM, the Database name as INTERID and the Company ID as CMPANYID.  The company ID will always be an integer, and the test company is usually -1.  The InterID is always a three letter word and potentially a number.  Example: DYN01, DYN02, etc.  The Company Name will be the value that you fill out during setup.  These tables are how to find your GP company ID and they will provide additional information about your company if you want to look further by selecting all columns.

While looking for how to find your GP company ID may seem somewhat difficult in GP it is typically best to look directly at SQL.  GP does not have a great method for looking up company information and you will likely still be asking yourself how to find your GP company ID.  Again, because this information is typically only required for an integraiton or special third party addins it is unlikely that GP will show you how to find your GP company ID anytime soon.

If you are looking for more information on how to find your GP company ID

Check out this excellent SQL posting from Victoria Yudin about how to find your GP company ID in SQL.

HOW TO: Write Your First Outlook 2010 Addin

Writing an Outlook 2010 Addin is a very easy task given the tools that Microsoft provides.  While it does require some knowledge about what you are doing and where you are going, overall the Outlook 2010 addin functionality is a robust system that gives you the flexibility you need to get the information required.

I am a big supporter of Outlook as an email client as well as a scheduling tool.  A huge advantage that Microsoft Office has over most of the competition is the ability to easily write addins and communicate with all other tools that are Office related.  An Outlook 2010 addin is no exception to this and it provides a great way to embed ideas and activities into your own interface without much work.  Developing an Outlook 2010 addin has been designed to be so easy that you can start right away simply by installing Visual Studio 2010 and Office 2010.

Creating an Outlook 2010 Addin

To get started an Outlook 2010 addin, Open up the New Solution window and navigate to the Office -> 2010 Section of your preferred language.

outlook 2010 addin - new  solution window

As a test, let’s create a custom tab in our Outlook and use it to pop a Hello World window.  To do this, open the Add New Item window and navigate to Office -> Ribbon (Visual Designer)

outlook 2010 addin - new  item window

How to implement an Outlook 2010 Addin that shows a new ribbon

To choose which Ribbon you are modifying, select the Ribbon Type on the right hand side.  For this example I chose the Explorer Ribbon so it shows up directly on the Office 2010 main ribbon.

On the left side of the Ribbon Designer you will get some nice pre-built Microsoft Office controls to use, simply drag a button onto the Ribbon.

outlook 2010 addin - new  ribbon button

At this point simply double click your button to bring up an event and type in the Message Box command to print Hello World.  If your Outlook is running you will need to close it to deploy.  Once closed, run your add-in through debug mode and it will pop up Outlook with your added loaded into it.

outlook 2010 addin - hello world

Writing an Outlook 2010 addin can be very simple or very complex based on what you want to do with it.  Just like with any coding you should start easy and have fun to start.  If you are interested in more information about writing an Outlook 2010 addin check out this MSDN article for more detail.