Here is a sample VB.net code I created the other day that shows how to extract data from IDO's and bind the data to a data grid.
The below code may not format well in this post so if you want me to email you the zip file with the source let me know.
NOTE: this Can be easily converted to C# via Code Converter C# to VB and VB to C# – Telerik
I put xxxxxxx where I had sensitive info like user, password, config name. Please substitute with your values.
Imports Newtonsoft.Json
Imports System
Imports System.Collections.Generic
Imports System.Data
Imports System.Web.Script.Serialization
Imports System.Windows.Forms
Imports System.Xml
''' <summary>
''' ==============================================================================================================================================
''' DATE - May 6, 2021
''' DEPENDENCIES - Newtonsoft.JSON nuGet package
''' FORM DESCRIPTION - This form shows how to use the Mongoose REST API version 2 to load data (readonly) from 3 CSI IDO's into a data grid view.
''' The document mg_2021.xx_Integrating IDOs with External Applications.pdf in the solutions explorer
''' was used as a reference starting on page 121 "REST API, Version 2".
'''
''' API Methods used
''' ----------------
''' page 128 - GetConfigurations
''' page 134 - GetSecurityToken
''' page 137 - Load Collection
'''
'''
''' ==============================================================================================================================================
''' </summary>
Public Class frmLoadCollection
Private m_Token As String = String.Empty
Public Sub New()
InitializeComponent()
End Sub
#Region "Form Events"
Private Sub frmLoadCollection_Resize(sender As Object, e As EventArgs) Handles Me.Resize
DataGridView1.Width = Me.Width
DataGridView1.Height = Me.Height
End Sub
Private Sub frmLoadCollection_Load(sender As Object, e As EventArgs) Handles Me.Load
'// Get the list of configurations for xxxxxand load into the Configuration/Environment drop down list
Call GetConfigurations()
cboConfig.SelectedItem = "xxxxxxx"
End Sub
Private Sub LoadCollection_Click(sender As Object, e As EventArgs) Handles LoadCollection.Click
Dim requestURL As String = ""
If String.IsNullOrEmpty(Convert.ToString(IDOName.SelectedItem)) Then
MessageBox.Show("Please select IDO.")
Else
Dim theReturnList As Object
Cursor = Cursors.WaitCursor
'// Get a token. This is based on the user id, password, and configuration/environment specified on the form
If String.IsNullOrEmpty(m_Token) Then
m_Token = Me.GetTokenV2API()
End If
'// If a valid token, then call the API to retrieve the IDO data selected from the IDO drop down on the form
If m_Token IsNot Nothing Then
Select Case IDOName.SelectedItem
Case = "SLItems"
requestURL = "">csi10a.erpsl.inforcloudsuite.com/.../SLItems
theReturnList = CallAPIv2(requestURL)
Call DisplayItems(theReturnList)
Case = "Usernames"
requestURL = "">csi10a.erpsl.inforcloudsuite.com/.../UserNames
theReturnList = CallAPIv2(requestURL)
Call DisplayUserNames(theReturnList)
Case = "ue_MID_Employee"
requestURL = "">csi10a.erpsl.inforcloudsuite.com/.../ue_MID_Employees
theReturnList = CallAPIv2(requestURL)
Call DisplayEmployees(theReturnList)
End Select
End If
Cursor = Cursors.Default
End If
End Sub
''' <summary>
''' When the configuration drop down changes, clear the token and force it to get a new one with the userid and password
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub cboConfig_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboConfig.SelectedIndexChanged
m_Token = ""
LoadCollection.Enabled = False
Select Case cboConfig.SelectedItem
Case Is = "xxxxxxxx"
txtUserID.Text = "xxxxxx"
txtPassword.Text = "xxxxxxx"
LoadCollection.Enabled = True
Case Else
txtUserID.Text = ""
txtPassword.Text = ""
End Select
End Sub
Private Sub txtUserID_TextChanged(sender As Object, e As EventArgs) Handles txtUserID.TextChanged
If txtUserID.Text.Length > 0 Then
LoadCollection.Enabled = True
Else
LoadCollection.Enabled = False
End If
End Sub
#End Region
#Region "Rest API v2 calls"
Private Function CallAPIv2(RequestURL As String, Optional Type As String = "Items") As Object
Using client = New System.Net.WebClient()
client.Headers.Add("Content-Type:application/json")
client.Headers.Add("Accept:application/json")
client.Headers.Add("Authorization", m_Token)
Dim result As String = client.DownloadString(RequestURL)
Dim col As Integer = 0
Dim jsSerializer As JavaScriptSerializer = New JavaScriptSerializer()
Dim json_data As Object = jsSerializer.DeserializeObject(result)
Dim obj2 As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
obj2 = CType((json_data), Dictionary(Of String, Object))
Dim item = CType(obj2(Type), Object())
Return item
End Using
End Function
Private Function GetTokenV2API() As String
Try
Using client = New System.Net.WebClient()
Dim requestUrl As String = "">csi10a.erpsl.inforcloudsuite.com/.../" & cboConfig.SelectedItem & "/" & txtUserID.Text & "/" & txtPassword.Text
Dim result As String = client.DownloadString(requestUrl)
Dim tokenJson = JsonConvert.SerializeObject(result)
Dim jsonResult = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(result)
m_Token = jsonResult.Item("Token")
If m_Token Is Nothing Then
MsgBox(result)
End If
Return m_Token
End Using
Catch ex As Exception
Throw
End Try
End Function
Private Sub GetConfigurations()
Dim RetVal As Object
Dim requestURL As String = "">csi10a.erpsl.inforcloudsuite.com/.../configurations
RetVal = CallAPIv2(requestURL, "Configurations") '// Note no token is needed for this call
cboConfig.DataSource = RetVal
End Sub
#End Region
#Region "Translate JSON into datatable object to display in data grid"
Private Sub DisplayUserNames(theReturnList As Object)
Dim dt As DataTable = New DataTable()
Dim theRow As DataRow
Dim colUserName As New DataColumn("Username")
Dim colEditLevel As New DataColumn("EditLevel")
dt.Columns.Add(colUserName)
dt.Columns.Add(colEditLevel)
For Each items In theReturnList
Dim itm = CType(items, Object)
Dim UserName As String = itm("Username")
Dim EditLevel As String = itm("EditLevel")
theRow = dt.NewRow
theRow.Item(colUserName) = UserName
theRow.Item(colEditLevel) = EditLevel
dt.Rows.Add(theRow)
Next
DataGridView1.DataSource = dt
Me.Text = "v2 API Example: Records Displayed: " & dt.Rows.Count
End Sub
Private Sub DisplayItems(theReturnList As Object)
Dim dt As DataTable = New DataTable()
Dim theRow As DataRow
Dim colItem As New DataColumn("Item")
Dim colDescription As New DataColumn("Description")
Dim colUM As New DataColumn("UM")
Dim colMatlType As New DataColumn("MatlType")
Dim colPMTCode As New DataColumn("PMTCode")
Dim colProductCode As New DataColumn("ProductCode")
Dim colAbcCost As New DataColumn("ABCCost")
Dim colCostType As New DataColumn("CostType")
Dim colCostMethod As New DataColumn("CostMethod")
Dim colProdType As New DataColumn("ProdType")
Dim colStat As New DataColumn("Stat")
Dim colRevision As New DataColumn("Revision")
Dim colSerialTracked As New DataColumn("SerialTracked")
dt.Columns.Add(colItem)
dt.Columns.Add(colDescription)
dt.Columns.Add(colUM)
dt.Columns.Add(colMatlType)
dt.Columns.Add(colPMTCode)
dt.Columns.Add(colProductCode)
dt.Columns.Add(colAbcCost)
dt.Columns.Add(colCostType)
dt.Columns.Add(colCostMethod)
dt.Columns.Add(colProdType)
dt.Columns.Add(colStat)
dt.Columns.Add(colRevision)
dt.Columns.Add(colSerialTracked)
For Each items In theReturnList
Dim itm = CType(items, Object)
Dim ItemNumber As String = itm("Item")
Dim Description As String = itm("Description")
Dim UM As String = itm("UM")
Dim MatlType As String = itm("MatlType")
Dim PMTCode As String = itm("PMTCode")
Dim ProductCode As String = itm("ProductCode")
Dim AbcCost As String = itm("AbcCode")
Dim CostType As String = itm("CostType")
Dim CostMethod As String = itm("CostMethod")
Dim ProdType As String = itm("ProdType")
Dim Stat As String = itm("Stat")
Dim Revision As String = itm("Revision")
Dim SerialTracked As String = itm("SerialTracked")
theRow = dt.NewRow
theRow.Item(colItem) = ItemNumber
theRow.Item(colDescription) = Description
theRow.Item(colUM) = UM
theRow.Item(colMatlType) = MatlType
theRow.Item(colPMTCode) = PMTCode
theRow.Item(colProductCode) = ProductCode
theRow.Item(colAbcCost) = AbcCost
theRow.Item(colCostType) = CostType
theRow.Item(colCostMethod) = CostMethod
theRow.Item(colProdType) = ProdType
theRow.Item(colStat) = Stat
theRow.Item(colRevision) = Revision
theRow.Item(colSerialTracked) = SerialTracked
dt.Rows.Add(theRow)
Next
DataGridView1.DataSource = dt
Me.Text = "v2 API Example: Records Displayed: " & dt.Rows.Count
End Sub
Private Sub DisplayEmployees(theReturnList As Object)
Dim dt As DataTable = New DataTable()
Dim theRow As DataRow
Dim colEmpID As New DataColumn("EmpID")
Dim colEmpName As New DataColumn("EmpName")
dt.Columns.Add(colEmpID)
dt.Columns.Add(colEmpName)
For Each items In theReturnList
Dim itm = CType(items, Object)
Dim EmpID As String = itm("EmpID")
Dim EmpName As String = itm("EmpName")
theRow = dt.NewRow
theRow.Item(colEmpID) = EmpID
theRow.Item(colEmpName) = EmpName
dt.Rows.Add(theRow)
Next
DataGridView1.DataSource = dt
Me.Text = "v2 API Example: Records Displayed: " & dt.Rows.Count
End Sub
#End Region
End Class