Dearsystems Dear Inventory API Integration

Dear Inventory API Integration.

Dear Inventory is an inventory management system from DearSystems that is used by thousands of businesses over the world. Although a great tool it doesn't work with most web sites or CRM systems out of the box and that is where people like me can help.

Dear provide an API tool with the Dear Inventory system to allow developers to access the system and integrate with your other systems. By using the Dear Inventory API you can have portals for your customers and even place orders from your web site and into the Dear Inventory system without you needing to manually do this.

To discuss integrating your system with Dear please get in touch.

For other developers looking into doing this I've provided a quick example that shows how to do it.

Making the Dearsystems Dear Inventory API work with your Visual Studio Project

On a recent project I had to integrate a web site into the DearSystems Dear API.

The first thing I did was to Google to see who had already managed to get an example of this working but couldn’t find any good examples, especially in Visual Studio and very specifically in Visual Basic.

It took me a while to actually get anything working and I had to go back and forth to Dear Support, but eventually I managed to get it something working and the client happy.

So to make things easier for you I’ve created a very basic example that just returns a customers’ details from their Dear ID and displays them in a message box on the screen.

There is obviously a lot more you can do with the Dear API but this should get you heading in the right direction.

Note, you will need to have then Newtonsoft JSON (http://www.newtonsoft.com/json) tools installed for this example to work.

Alternatively, if you would like me to develop the interface for you please contact us to discuss further.

Create a class called DearAPI, then copy in the code below.

Imports Microsoft.VisualBasic
Imports System.Net
Imports Newtonsoft.Json
Public Class DearAPI
    Inherits System.Web.UI.Page
    Private mstrApplicationKey As String = ""
    Private mstrAccountID As String = ""
    Public Sub New(strApplicationKey As String, strAccountID As String)
        mstrApplicationKey = strApplicationKey
        mstrAccountID = strAccountID
    End Sub
    '
    '   Customer
    '
    Public Class Address
        Public Property Line1 As String
        Public Property Line2 As String
        Public Property City As String
        Public Property State As String
        Public Property Postcode As String
        Public Property Country As String
        Public Property Type As String
        Public Property DefaultForType As Boolean
    End Class
    Public Class Contact
        Public Property Name As String
        Public Property Phone As String
        Public Property Fax As String
        Public Property Email As String
        Public Property Website As String
        Public Property [Default] As Boolean
        Public Property Comment As String
    End Class
    Public Class Customer
        Public Property Addresses As Address()
        Public Property Contacts As Contact()
        Public Property ID As String
        Public Property Name As String
        Public Property Currency As String
        Public Property PaymentTerm As String
        Public Property Discount As Single
        Public Property TaxRule As String
        Public Property Carrier As String
        Public Property SalesRepresentative As String
        Public Property Location As String
        Public Property Comments As String
        Public Property AccountReceivable As String
        Public Property RevenueAccount As String
        Public Property PriceTier As String
        Public Property TaxNumber As String
        Public Property AdditionalAttribute1 As String
        Public Property AdditionalAttribute2 As String
        Public Property AdditionalAttribute3 As String
        Public Property AdditionalAttribute4 As String
        Public Property AdditionalAttribute5 As String
        Public Property AdditionalAttribute6 As String
        Public Property AdditionalAttribute7 As String
        Public Property AdditionalAttribute8 As String
        Public Property AdditionalAttribute9 As String
        Public Property AdditionalAttribute10 As String
        Public Property AttributeSet As String
        Public Property Tags As String
        Public Property Status As String
        Public Property LastModifiedOn As Object
        Public Property CreditLimit As Single
    End Class
    Public Class CustData
        Public Property Customers As Customer()
    End Class
    Public ReadOnly Property Customers(strID As String) As Customer
        Get
            Dim myCustomers As CustData
            Dim strCustomers As String
            Dim wcDearSystem = New WebClient()
            Dim jsonSettings As New JsonSerializerSettings
            '
            jsonSettings.NullValueHandling = NullValueHandling.Ignore
            '
            Try
                '
                '   Log into the DearSystems API
                '
                With wcDearSystem
                    .UseDefaultCredentials = True
                    .BaseAddress = "https://inventory.dearsystems.com/DearApi/"
                    .Headers.Add("api-auth-applicationkey", mstrApplicationKey)
                    .Headers.Add("api-auth-accountid", mstrAccountID)
                    .Headers.Add(HttpRequestHeader.Accept, "application/json")
                    .Headers.Add("Content-Type", "application/json")
                End With
                '
                strCustomers = wcDearSystem.DownloadString("https://inventory.dearsystems.com/DearApi/Customers?ID=" & strID)
                myCustomers = JsonConvert.DeserializeObject(Of CustData)(strCustomers, jsonSettings)
                '
                '   Return customer
                '
                Return myCustomers.Customers(0)
            Catch
                '
                '   Return nothing, this will hide errors so you might want to improve this bit, but you get the idea
                '
                Return Nothing
            End Try
        End Get
    End Property
End Class

                    

Create a VB form, In the example it is called Test.ASPX and then open up the code behind. Copy below into it.

Partial Class Test
    Inherits System.Web.UI.Page
    Private Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load
        Dim myDearApi As New DearAPI("***your application key goes here***", "***your account id goes here***")
        '
        Dim myCustomer As DearAPI.Customer = myDearApi.Customers("***one of your customer ids goes here***")
        '
        If Not IsNothing(myCustomer) Then
            MsgBox(myCustomer.Name & " - " & myCustomer.Addresses(0).City)
        Else
            MsgBox("Nothing returned")
        End If
    End Sub
End Class