How to integrate zoom meeting in .net core application

I have created a basic app in Zoom market place and got the api key and secret key.

using the following code to create a meeting url.

        var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
        var now = DateTime.UtcNow;
        var apiSecret = "--";
        byte[] symmetricKey = Encoding.ASCII.GetBytes(apiSecret);

        var tokenDescriptor = new SecurityTokenDescriptor
        {
            Issuer = "---",
            Expires = now.AddSeconds(300),
            SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256),
        };
        var token = tokenHandler.CreateToken(tokenDescriptor);
        var tokenString = tokenHandler.WriteToken(token);

        var client = new RestClient("https://api.zoom.us/ve/users/me/meetings");
        var request = new RestRequest(Method.Get.ToString());
        request.RequestFormat = DataFormat.Json;
        request.AddJsonBody(new { topic = "Meeting with Ussain", duration = "10", start_time = "2021-05-20T05:00:00", type = "2" });
        request.AddHeader("authorization", String.Format("Bearer {0}", tokenString));
        request.AddHeader("Content-Type", "application/json");

        var restResponse = client.Execute<RestRequest>(request);
        HttpStatusCode statusCode = restResponse.StatusCode;
        int numericStatusCode = (int)statusCode;
        var jObject = JObject.Parse(restResponse.Content);
        var Host = (string)jObject["start_url"];
        var Join = (string)jObject["join_url"];
        var Code = Convert.ToString(numericStatusCode);

        return NoContent();

I am getting the error response, which does not have any other details.

Please help me with the steps to create zoom meeting in .net

i changed the endpoint to https://api.zoom.us/v2/users and i get invalid access token

Hi @thendral.d
Make sure to use the correct endpoint to create a meeting:

If you are working with a server-to-server OAuth app, please review our documentation to ensure that you are generating the token correctly

Hi,

I am using the https://api.zoom.us/v2/users/thendral/meetings api, Can you please confirm this is correct?

Thanks,
Thendral

Hi @thendral.d make sure to pass your email as a “user_id” or the “me” parameter

I did , but still getting the error response

As per your previous reply

  1. I have created account level server-to-server app
  2. Got the client id,client secret and account id
  3. made a post call to https://zoom.us/oauth/token
  4. I get error “not found”
  5. When I try the same in Postmand I get “Invalid grant type” error

I used the following code

       var tokenHandler = new System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler();
       var now = DateTime.UtcNow;
       var apiSecret = "ak3bP9M6GNkXICUDNbR9VHoL1k5Evprn";
       byte[] symmetricKey = Encoding.ASCII.GetBytes(apiSecret);

       var tokenDescriptor = new SecurityTokenDescriptor
       {
           Issuer = "5wJdnzpjSPyQwn4MrhvyZg",
           Expires = now.AddSeconds(300),
           SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256),
       };
       var token = tokenHandler.CreateToken(tokenDescriptor);
       var tokenString = tokenHandler.WriteToken(token);

       var encoding = new System.Text.ASCIIEncoding();
       byte[] messageBytesTest = encoding.GetBytes("fuux1tbRSmbShAIedMw7w:YiFHa36YpikhfL4U6MjLLb9ZDy9woZVE");
       string msgHashPreHmac = System.Convert.ToBase64String(messageBytesTest);
       var client1 = new RestClient("https://zoom.us/oauth/token");
       var request1 = new RestRequest(Method.Post.ToString());
       //request1.RequestFormat = DataFormat.Json;
       //request1.AddStringBody("grantype:account_credentials", "account_id:FkmZHX8iQ5OnYFjWPFkShg");
       request1.AddHeader("Content-Type", "application/x-www-form-urlencoded");
       request1.AddHeader("authorization", String.Format("Basic {0}", msgHashPreHmac));
       request1.AddParameter("grantype:account_credentials", ParameterType.RequestBody);
       request1.AddParameter("account_id:FkmZHX8iQ5OnYFjWPFkShg", ParameterType.RequestBody);


       var restResponse1 = client1.Execute<RestRequest>(request1);

       var client = new RestClient("https://api.zoom.us//v2/users/me/meetings");
       var request = new RestRequest(Method.Post.ToString());
       request.RequestFormat = DataFormat.Json;
       request.AddJsonBody(new { topic = "Meeting with Ussain", duration = "10", start_time = "2021-05-20T05:00:00", type = "2" });
       request.AddHeader("authorization", String.Format("Bearer {0}", tokenString));
       request.AddHeader("Content-Type", "application/json");

       var restResponse = client.Execute<RestRequest>(request);
       HttpStatusCode statusCode = restResponse.StatusCode;
       int numericStatusCode = (int)statusCode;
       var jObject = JObject.Parse(restResponse.Content);
       var Host = (string)jObject["start_url"];
       var Join = (string)jObject["join_url"];
       var Code = Convert.ToString(numericStatusCode);

       return NoContent();

@thendral.d I’ll do something like this

Part 1, get an access token using S2S App. Use the client id, client secret and account id to get access token.

using Newtonsoft.Json;
using System.Text;
using System.Text.Json;



    public class s2soauth
    {

        public static Task S2SOauth(HttpContext context)
        {
            return Task.Run(async () =>
            {

                string s2s_oauth_client_id = Environment.GetEnvironmentVariable("S2S_OAUTH_CLIENT_ID"); 
                string s2s_oauth_client_secret = Environment.GetEnvironmentVariable("S2S_OAUTH_CLIENT_SECRET"); 
                string s2s_oauth_account_id = Environment.GetEnvironmentVariable("S2S_OAUTH_ACCOUNT_ID");


                // Access the environment variables
                var clientId = s2s_oauth_client_id;
                var clientSecret = s2s_oauth_client_secret;
                var accountId = s2s_oauth_account_id;
                var oauthUrl = $"https://zoom.us/oauth/token?grant_type=account_credentials&account_id={accountId}";

                try
                {
                    // Create the Basic Authentication header
                    var authHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));

                    // Initialize HttpClient
                    using var client = new HttpClient();

                    // Create request message
                    var request = new HttpRequestMessage(HttpMethod.Post, oauthUrl);
                    request.Headers.Add("Authorization", $"Basic {authHeader}");

                    // Send request and get response
                    var response = await client.SendAsync(request);

                    // Check if the request was successful (status code 200)
                    if (response.IsSuccessStatusCode)
                    {
                        // Parse the JSON response to get the access token
                        var jsonResponse = await response.Content.ReadAsStringAsync();
                        var accessToken = JsonDocument.Parse(jsonResponse).RootElement.GetProperty("access_token").GetString();

                        // Set the "Content-Type" header to "application/json"
                        await context.Response.WriteAsync(JsonConvert.SerializeObject(accessToken));
                      
                    }
                    else
                    {
                        await context.Response.WriteAsync($"OAuth Request Failed with Status Code: {response.StatusCode}");
                      
                    }
                }
                catch (Exception e)
                {
                    await context.Response.WriteAsync($"An error occurred: {e.Message}");
                   
                }


            });
        }

   
    }

1 Like

@thendral.d

next I’ll use the access token to create a meeting with the code below

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class callapi
{
    public static Task CallAPI(HttpContext context)
    {
        return Task.Run(async () =>
        {
            // Fetch access_token from query string
            var access_token = context.Request.Query["access_token"];

            // Meeting data
            var meeting_data = new
            {
                topic = "hello world",
                type = 2,
                start_time = "2023-10-01T10:00:00Z",
                duration = 120,
                password = "12345678",
                agenda = "40 mins limit demonstration",
                pre_schedule = false,
                timezone = "Asia/Singapore",
                default_password = false
            };

            // Zoom API endpoint
            var api_url = "https://api.zoom.us/v2/users/me/meetings";

            // Headers for the request
            var headers = new
            {
                Authorization = $"Bearer {access_token}",
                Content_Type = "application/json",
                Accept = "application/json"
            };

            // Send POST request to create meeting
            using var client = new HttpClient();
            using var request = new HttpRequestMessage(HttpMethod.Post, api_url);
            request.Content = new StringContent(JsonSerializer.Serialize(meeting_data), Encoding.UTF8, "application/json");

            foreach (var header in headers.GetType().GetProperties())
            {
                request.Headers.Add(header.Name, header.GetValue(headers).ToString());
            }

            var response = await client.SendAsync(request);

            // Return response
            await context.Response.WriteAsync("Meeting Details: " + await response.Content.ReadAsStringAsync());
        });


    }
}


 
1 Like

@chunsiong.zoom Thank you , it worked now

Now I can successfully get the start and join url, now I need to know how I can embed that in angular. Can someone please help me with that?

Idea of the project is ,

  1. There will be multiple users in our application.
  2. On click of a button “user A” and “user B” should join the meeting.
  3. There will be multiple meeting scheduled between the users.

I want to accomplish this in Angular and .Net core

So far I have done the following.

  1. Created a Server to server app in zoom market place.
  2. Got the access token and start and join url from .Net

My questions are

  1. Will I get the same access token every time ?
  2. With that access token will I be able to make different meeting windows in angular between users?
  3. How can I embed the start url in angular?

Please help me with the questions.

I followed the below link to embed zoom meeting .

But I get invalid sdk key error. I created server to server app and got the client id. I hope client id is the sdk key. Can someone please help me with this?

@chunsiong.zoom Can you please help me with this one if you have any idea?

@thendral.d for meeting SDK, you will need to use the client ID and client secret from a General App with Meeting SDK enabled.

I created meeting from servertoserver app. used the component view to embed the meeting in angular.

When I leave or close or end the meeting and try to join in the same meeting again in the same browser I get the following error.

ERROR Error: Uncaught (in promise): Object: {“type”:“INVALID_OPERATION”,“reason”:“Duplicated join operation”}

Also I want to know how i can end the meeting programmatically from .net.

@chunsiong.zoom Please provide your inputs.

@thendral.d are you trying to join the same meeting from the 2 different browser tab? That is not supported

Steps I followed

  1. I created a meeting and end it in a browser. (Meeting perfectly gets loaded in meetingSDKElement element)
  2. Created another meeting and try to join in the same browser , the meeting is started in (zoom.us). But it is not loaded in “meetingSDKElement” element .

Can you please help me with this?

@chunsiong.zoom please help me.

@thendral.d you cannot have 2 instances of the web SDK running on the same browser.

Is it possible with Web SDK Client view? @chunsiong.zoom

I should be able to join multiple meetings once previous meeting is completed in the same browser. How can I achieve this? Please help me with any workarounds.