title: Creating a Microsoft Teams Meeting using VB.NET and Microsoft Graph API
body: <p>I have created a login authentication using the Microsoft Graph API which means after I sign in, as a result, I have the access token of the current user signed-in. My next step is to create a Microsoft Teams Meeting on behalf of the current user signed-in.</p>
  
  <p>I have tried to follow the Microsoft documentation <a href="https://docs.microsoft.com/en-us/graph/api/application-post-onlinemeetings?view=graph-rest-beta&amp;tabs=csharp" rel="nofollow noreferrer">Application POST onlinemeetings</a>, where It shows the required steps to achieve this scenario. </p>
  
  <p>Unfortunately, they didn't provide an example of how it can be achieved in VB.Net (which is not a big deal because I have converted the code to VB).</p>
  
  <p>Currently, I am stuck on sending a POST request to generate this meeting based on the hard coded values when the user clicks on the button.</p>
  
  <p>Please have a look at the code below:</p>
  
  <pre><code>Imports System.IO
  Imports System.Net
  Imports System.Net.Http
  Imports System.Net.Http.Headers
  Imports System.Threading.Tasks
  Imports Microsoft.Graph
  Imports Microsoft.IdentityModel.Clients.ActiveDirectory
  Imports Newtonsoft.Json
  Imports Newtonsoft.Json.Linq
  
  Public Class _Default
      Inherits Page
  
      Private Shared httpClient As HttpClient = New HttpClient()
      Private Shared context As AuthenticationContext = Nothing
      Private Shared credential As ClientCredential = Nothing
      Private Shared graphClient As GraphServiceClient
      Private Shared authprovider As IAuthenticationProvider
  
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
          Dim code = HttpContext.Current.Request.QueryString("Code")
          If Not Page.IsPostBack Then
              If code &lt;&gt; "" Then
                  Dim url = "https://login.microsoftonline.com/common/oauth2/v2.0/token"
                  Dim myParameters = "grant_type=authorization_code&amp;code=" &amp; code &amp; "&amp;redirect_uri=https://localhost:4312/&amp;client_id=CLIENTID&amp;client_secret=CLIENTSECRET"
                  Dim wb = New WebClient
                  wb.Headers(HttpRequestHeader.ContentType) = "application/x-www-form-urlencoded"
                  Dim response = wb.UploadString(url, "POST", myParameters)
                  responseToken.Text = response
                  Success.Text = "O365 login successful. Below is the response token"
                  Dim SurroundingClass = JsonConvert.DeserializeObject(Of SurroundingClass)(response)
  
  
                  Dim rss As JObject = JObject.Parse(response)
                  Dim token = rss.SelectToken("access_token")
                  Dim res = GetUsers(token)
  
  
  
              End If
          End If
  
      End Sub
  
      Private Shared Async Function GetUsers(ByVal result As String) As Task(Of String)
          Try
              Dim users As String = Nothing
              Dim querystring As String = "api-version=1.6"
              Dim uri = "https://graph.microsoft.com/v1.0/me"
              httpClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", result)
              httpClient.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
  
              Dim User = GetMeAsync().Result
              Console.WriteLine($"Welcome {User.DisplayName}!\n")
  
              Dim getResult = Await httpClient.GetAsync(uri)
  
              If getResult.Content IsNot Nothing Then
                  users = Await getResult.Content.ReadAsStringAsync()
              End If
  
              Return users
          Catch ex As Exception
              Throw ex
          End Try
      End Function
  
        Protected Sub tes_Click(sender As Object, e As EventArgs)
          Try
  
              'Dim fr As System.Net.HttpWebRequest
              Dim client_id = ""// App Client ID'
              Dim uri = "https://localhost:4312/"
  
              Dim targetURI As String = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=" &amp; client_id &amp;
                                       "&amp;redirect_uri=" &amp; uri &amp; "&amp;response_type=code&amp;scope=openid+Mail.Read"
              Response.Redirect(targetURI)
  
          Catch ex As System.Net.WebException
              'Error in accessing the resource, handle it
          End Try
      End Sub
  
         Public Shared Async Function CreateMeeting() As Task(Of OnlineMeeting)
  
      Try
          graphClient = New GraphServiceClient(authprovider)
  
          Dim onlineMeeting = New OnlineMeeting With {
              .StartDateTime = DateTimeOffset.Parse("2020-04-23T21:33:30.8546353+00:00"),
              .EndDateTime = DateTimeOffset.Parse("2020-04-23T22:03:30.8566356+00:00"),
              .Subject = "Application Token Meeting",
              .Participants = New MeetingParticipants With {
              .Organizer = New MeetingParticipantInfo With {
              .Identity = New IdentitySet With {
                  .User = New Identity With {
                      .Id = "MYID"
                  }
              }
          }
      }
  }
  
          Dim encodings As New UTF8Encoding
          Dim serializer As New JavaScriptSerializer()
          Dim arrayJson As String = serializer.Serialize(onlineMeeting)
          Dim result As String = Nothing
  
          Dim postRequest As HttpWebRequest = DirectCast(WebRequest.Create("https://graph.microsoft.com/v1.0/me/onlineMeetings"), HttpWebRequest)
          postRequest.Method = "POST"
          postRequest.ContentType = "application/json"
          httpClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", Token)
  
          If postRequest.Method = "POST" Then
  
              Dim parsedContent As String = JsonConvert.SerializeObject(onlineMeeting)
              Dim encoding As ASCIIEncoding = New ASCIIEncoding()
              Dim bytes As Byte() = encoding.GetBytes(parsedContent)
              Dim newStream As Stream = postRequest.GetRequestStream()
              newStream.Write(bytes, 0, bytes.Length)
              newStream.Close()
  
          End If
  
          Dim createMeetings = Await graphClient.Communications.OnlineMeetings.Request().AddAsync(onlineMeeting)
  
          Console.WriteLine("The meeting has been created")
  
          Return createMeetings
  
      Catch ex As ServiceException
  
          Console.WriteLine($"Error while creating the meeting: {ex.Message}")
          Return Nothing
      End Try
  
  End Function
  
    Public Sub InvokeMeeting(sender As Object, e As EventArgs)
  
  
      Try
          Dim testing = CreateMeeting()
  
  
      Catch ex As Exception
  
      End Try
  
      End Sub
  </code></pre>
  
  <p>PS: I have added the permission required to call this API to be able to create a Teams meeting.</p>
  
  <p>Any suggestions on how to achieve the following scenario?</p>
  
  <p>Any help will be greatly appreciated.
  Thank you!</p>