VB.NET

Voici ci-dessous un exemple d'utilisation de l'API ClicRDV en VB.NET. On utilise ici l'authentification HTTP Basic, et un format d'API en XML.

Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Xml

Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim str As String

Try

  ' Credentials
  Dim apikey = "xxxxxx"
  Dim user = "me@exemple.com"
  Dim pwd = "myPwd"

  Dim baseUrl = "https://sandbox.clicrdv.com/api/v1"
  Dim url = baseUrl+"/groups/:group_id/calendars?format=xml&results=10&apikey=" + apikey

  ' Building the request
  request = DirectCast(WebRequest.Create(url), HttpWebRequest)

  ' Basic Authentification
  request.PreAuthenticate = True
  request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested
  Dim encodedHdr = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(user + ":" + pwd))
  request.Headers.Add("Authorization", "Basic " + encodedHdr)

  ' Reading response
  response = DirectCast(request.GetResponse(), HttpWebResponse)
  reader = New StreamReader(response.GetResponseStream())
  str = reader.ReadToEnd()

  ' Parsing XML and printing the name of each result
  Using xmlreader As XmlReader = xmlreader.Create(New StringReader(str))

    While xmlreader.ReadToFollowing("name")
      Console.WriteLine(xmlreader.ReadElementContentAsString())
    End While
  End Using

Catch ex As Exception
  Console.WriteLine(ex.Message)
Finally
  If Not response Is Nothing Then
    response.Close()
  End If
End Try