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
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}");
}
});
}
}
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());
});
}
}
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?
I created a meeting and end it in a browser. (Meeting perfectly gets loaded in meetingSDKElement element)
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 .
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.