Wednesday, July 31, 2013

VB.NET - Authenticate to ZenDesk V2 API

Using LINQPad 4,

Press F4 to import .NET dependencies.

Run LINQPad in "VB Program" mode.

Run the following VB code (replacing what is in curly brackets with your info):

Sub Main

        Dim wc As New System.Net.WebClient()

        Dim strZenDeskUsername As String = "{my email address}"

        Dim strZenDeskPassword As String = "{my password}"

        Dim strZenDeskAPIURL As String = "https://{my subdomain}"

 Dim request As System.Net.HttpWebRequest = 

        request.ContentType = "application/json"

        request.Credentials = New System.Net.NetworkCredential(strZenDeskUsername, strZenDeskPassword)

        request.Headers("Authorization") = strZenDeskUsername & ":" & strZenDeskPassword

        request.PreAuthenticate = True

        request.Accept = "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml"

        request.ContentLength = 0

        Dim resp As System.Net.HttpWebResponse = DirectCast(request.GetResponse(), System.Net.HttpWebResponse)

        Dim reader As New System.IO.StreamReader(resp.GetResponseStream())

        Dim tmp As String = reader.ReadToEnd()


        'Dim stream As New StringReader(tmp)

        'Dim ds As New DataSet()


        'Dim dt As DataTable = ds.Tables("user")

End Sub

No comments: