Simple VB.NET example

This example is a simple application in VB.NET located in:
[API installation folder]\Demos\VB.NET Simple

This is a Windows Application project in Visual Studio (.Net Framework with VB.NET).

Imports System.Net
Imports System.Net.Http
Imports Newtonsoft.Json
Imports System.Web

Public Class Form1
     'Please change these properties as required
     'Enter url here to web service API for example http://localhost:8888/api/
     Dim strApiURL As String = "http://localhost:8888/api/"

     'Create authentication model
     Public Class AuthenticateModel
           Public Property access_token As String
           Public Property refresh_token As String
           Public Property expires_in As Date
           Public Property token_type As String
           Public Property raw_claim As String
           Public Property success As Boolean
           Public Property message As String
     End Class

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
           'load two license types
           With cboLicense.Items 'do not change order
                  .Add("Editor") '190
                  .Add("Contributor") '191
           End With
            cboLicense.SelectedIndex = 1 'set default as Contributor
            Me.Text = strApplicationTitle
     End Sub

     Private Async Sub BtnLogin_Click(sender As Object, e As EventArgs) Handles BtnLogin.Click
           'This procedure performs login and consumes a license

           Try
                  Me.Cursor = Cursors.WaitCursor
                  BtnLogin.Enabled = False 'disable button during this procedure, enable at the end
                  Dim licenseId As Integer =191

                  'Validate all parameters
                  If (String.IsNullOrEmpty(strApiURL)) Then
                        'Display message if API address is missing
                        MsgBox("API address is missing. Please check your settings and try again." ,MsgBoxStyle.Information, strApplicationTitle)
                        Exit Sub
                  End If

                  If (String.IsNullOrEmpty(txtUsername.Text)) Then
                        'Display message if username is missing
                        MsgBox("Username is required." ,MsgBoxStyle.Information, strApplicationTitle)
                        txtUsername.Focus
                        Exit Sub
                  End If

                  If (String.IsNullOrEmpty(txtPassword.Text)) Then
                        'Display message if password is missing
                        MsgBox("Password is required." ,MsgBoxStyle.Information, strApplicationTitle)
                        txtPassword.Focus
                        Exit Sub
                  End If

                  'get license id from combo
                  If cboLicense.SelectedIndex = 1 Then licenseId = 190 Else licenseId = 191

                  'create full url with query parameters
                  Dim parameters = New With {.username = txtUsername.Text, .password = txtPassword.Text, .licenseId = licenseId}
                  Dim endopint = "Authentication/Authenticate?"
                  Dim url As String = GetUrlFromObject(Of Object)(parameters, endopint)

                  'Create Http client with Http request message
                  Dim client As HttpClient = New HttpClient()
                  Dim request = New HttpRequestMessage With { .Method = HttpMethod.[Post], .RequestUri = New Uri(url)}

                  'Send async request to get data from api
                  Dim response = Await client.SendAsync(request)

                  'Check if Api returned status code is Ok
                  If response.StatusCode = HttpStatusCode.OK Then
                        Dim responseString = Await response.Content.ReadAsStringAsync()
                        'Convert Api json result to authenticateModel
                        Dim myResponseObject As AuthenticateModel = JsonConvert.DeserializeObject(Of AuthenticateModel)(responseString)
                        If (myResponseObject.success And Not String .IsNullOrEmpty(myResponseObject.access_token)) Then
                              strApiToken = myResponseObject.access_token
                        Else
                              MsgBox(myResponseObject.message, MsgBoxStyle.Exclamation, strApplicationTitle)
                        End If

                        'enable these buttons
                        btnGetObjects.Enabled = True
                        btnGetObjectRecords.Enabled = True

                  Else
                        MsgBox("An error occurred. Please try again!", MsgBoxStyle.Information, strApplicationTitle)
                  End If

            Catch ex As Exception 'Manage errors
                  MsgBox("An error occurred. Make sure the URL is correct.", MsgBoxStyle.Exclamation, strApplicationTitle)
            Finally
                  Me.Cursor = Cursors.Default
                  BtnLogin.Enabled = True
            End Try

            'Dispaly info if user is authenticated or not
            lblLoginInfo.Text = If(Not String.IsNullOrEmpty(strApiToken), "User is authenticated.", "User is not authenticated.")

     End Sub