Last active
January 16, 2023 06:05
-
-
Save mayur-tendulkar/105fbe4f53ab0ac0fa62f209080d3bf3 to your computer and use it in GitHub Desktop.
blog-dyte-rest-create-meeting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public async Task<IActionResult> Create(Meeting meeting) | |
{ | |
// Check the provided meeting details | |
if (string.IsNullOrEmpty(meeting.Title)) | |
return StatusCode(400); | |
var json = JsonSerializer.Serialize(meeting); | |
var content = new StringContent(json, Encoding.UTF8, "application/json"); | |
var client = new HttpClient(); | |
var authToken = Convert.ToBase64String(Encoding.UTF8.GetBytes( | |
$"{Globals.OrganizationId}:{Globals.ApiKey}")); | |
client.BaseAddress = new Uri("https://api.cluster.dyte.in/"); | |
client.DefaultRequestHeaders.Authorization = | |
new AuthenticationHeaderValue("Basic", authToken); | |
//Create the meeting using Dyte REST APIs | |
var responseMessage = await client.PostAsync("/v2/meetings/", content); | |
var responseCode = responseMessage.EnsureSuccessStatusCode(); | |
if (responseCode.StatusCode != HttpStatusCode.Created) | |
{ | |
return BadRequest(responseCode); | |
} | |
var responseData = await responseMessage.Content.ReadAsStringAsync(); | |
var responseObject = JsonSerializer.Deserialize<CreateMeetingResponse>(responseData); | |
//Store the meeting using Azure Table Storage | |
var tableClient = new TableClient(Globals.AzureStorageUri, Globals.AzureTableName); | |
await tableClient.CreateIfNotExistsAsync(); | |
var entity = new TableEntity(Globals.OrganizationId, responseObject.Data.MeetingId); | |
await tableClient.AddEntityAsync(entity); | |
//Return created meeting object | |
return Created(string.Empty, responseObject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment