private Task UpdateRegistrantsStatusAsync(long meetingId, IEnumerable <string> registrantIds, string status, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("action", status); data.AddPropertyIfValue("registrants", registrantIds.ToArray()); return(_client .PutAsync($"meetings/{meetingId}/recordings/registrants/status") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsMessage()); }
/// <summary> /// Update monitor settings /// </summary> /// <param name="username">The sub user.</param> /// <param name="email">The email address to receive the monitor emails.</param> /// <param name="frequency">The frequency.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The <see cref="MonitorSettings" />. /// </returns> public Task <MonitorSettings> UpdateMonitorSettingsAsync(string username, Parameter <string> email = default(Parameter <string>), Parameter <int> frequency = default(Parameter <int>), CancellationToken cancellationToken = default(CancellationToken)) { var data = new JObject(); data.AddPropertyIfValue("email", email); data.AddPropertyIfValue("frequency", frequency); return(_client .PutAsync($"{_endpoint}/{username}/monitor") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <MonitorSettings>()); }
/// <summary> /// Creates a scheduled webinar for a user. /// </summary> /// <param name="userId">The user Id or email address.</param> /// <param name="topic">Webinar topic.</param> /// <param name="agenda">Webinar description.</param> /// <param name="start">Webinar start time.</param> /// <param name="duration">Webinar duration (minutes).</param> /// <param name="password"> /// Password to join the webinar. Password may only contain the following characters: [a-z A-Z 0-9 @ /// - _ *]. Max of 10 characters. /// </param> /// <param name="settings">Webinar settings.</param> /// <param name="trackingFields">Tracking fields.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The new webinar. /// </returns> /// <exception cref="System.Exception">Thrown when an exception occured while creating the webinar.</exception> public Task <Webinar> CreateScheduledWebinarAsync(string userId, string topic, string agenda, DateTime start, int duration, string password = null, WebinarSettings settings = null, IDictionary <string, string> trackingFields = null, CancellationToken cancellationToken = default) { var data = new JObject { { "type", 5 } }; data.AddPropertyIfValue("topic", topic); data.AddPropertyIfValue("agenda", agenda); data.AddPropertyIfValue("password", password); data.AddPropertyIfValue("start_time", start.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")); data.AddPropertyIfValue("duration", duration); data.AddPropertyIfValue("timezone", "UTC"); data.AddPropertyIfValue("settings", settings); data.AddPropertyIfValue("tracking_fields", trackingFields?.Select(tf => new JObject { { "field", tf.Key }, { "value", tf.Value } })); return(_client .PostAsync($"users/{userId}/webinars") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsObject <Webinar>()); }
/// <summary> /// Creates a scheduled webinar for a user. /// </summary> /// <param name="userId">The user Id or email address.</param> /// <param name="topic">Webinar topic.</param> /// <param name="agenda">Webinar description.</param> /// <param name="start">Webinar start time.</param> /// <param name="duration">Webinar duration (minutes).</param> /// <param name="timeZone">The time zone for start time.</param> /// <param name="password">Password to join the webinar. By default the password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. This can be updated within Zoom account settings.</param> /// <param name="settings">Webinar settings.</param> /// <param name="trackingFields">Tracking fields.</param> /// <param name="templateId">Template Identifer. If passed in, Zoom advise using the userId in the <paramref name="userId"/> field, rather than email address.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The new webinar. /// </returns> /// <exception cref="System.Exception">Thrown when an exception occured while creating the webinar.</exception> public Task <ScheduledWebinar> CreateScheduledWebinarAsync(string userId, string topic, string agenda, DateTime start, int duration, TimeZones?timeZone = TimeZones.UTC, string password = null, WebinarSettings settings = null, IDictionary <string, string> trackingFields = null, string templateId = null, CancellationToken cancellationToken = default) { var data = new JObject() { { "type", 5 } }; data.AddPropertyIfValue("topic", topic); data.AddPropertyIfValue("agenda", agenda); data.AddPropertyIfValue("password", password); data.AddPropertyIfValue("start_time", start.ToZoomFormat(timeZone)); data.AddPropertyIfValue("duration", duration); data.AddPropertyIfEnumValue("timezone", timeZone); data.AddPropertyIfValue("settings", settings); data.AddPropertyIfValue("tracking_fields", trackingFields?.Select(tf => new JObject() { { "field", tf.Key }, { "value", tf.Value } })); data.AddPropertyIfValue("template_id", templateId); return(_client .PostAsync($"users/{userId}/webinars") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsObject <ScheduledWebinar>()); }
/// <summary> /// Update the details of a recurring meeting. /// </summary> /// <param name="meetingId">The meeting ID.</param> /// <param name="userId">The user Id or email address.</param> /// <param name="topic">Meeting topic.</param> /// <param name="agenda">Meeting description.</param> /// <param name="start">Meeting start time. If omitted, a 'Recurring meeting with no fixed time' will be created.</param> /// <param name="duration">Meeting duration (minutes).</param> /// <param name="recurrence">Recurrence information.</param> /// <param name="password">Password to join the meeting. Password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters.</param> /// <param name="settings">Meeting settings.</param> /// <param name="trackingFields">Tracking fields.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The async task. /// </returns> public Task UpdateRecurringMeetingAsync(long meetingId, string userId = null, string topic = null, string agenda = null, DateTime?start = null, int?duration = null, RecurrenceInfo recurrence = null, string password = null, MeetingSettings settings = null, IDictionary <string, string> trackingFields = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("topic", topic); data.AddPropertyIfValue("password", password); data.AddPropertyIfValue("agenda", agenda); data.AddPropertyIfValue("start_time", start?.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")); data.AddPropertyIfValue("duration", duration); data.AddPropertyIfValue("recurrence", recurrence); if (start.HasValue) { data.Add("timezone", "UTC"); } data.AddPropertyIfValue("settings", settings); data.AddPropertyIfValue("tracking_fields", trackingFields?.Select(tf => new JObject() { { "field", tf.Key }, { "value", tf.Value } })); return(_client .PatchAsync($"meetings/{meetingId}") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsMessage()); }
/// <summary> /// Updates an existing recurring webinar for a user. /// </summary> /// <param name="webinarId">The webinar ID.</param> /// <param name="topic">Webinar topic.</param> /// <param name="agenda">Webinar description.</param> /// <param name="start">Webinar start time.</param> /// <param name="duration">Webinar duration (minutes).</param> /// <param name="recurrence">Recurrence information.</param> /// <param name="password">Password to join the webinar. By default the password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. This can be updated within Zoom account settings.</param> /// <param name="settings">Webinar settings.</param> /// <param name="trackingFields">Tracking fields.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The async task. /// </returns> public async Task UpdateRecurringWebinarAsync(long webinarId, string topic = null, string agenda = null, DateTime?start = null, int?duration = null, RecurrenceInfo recurrence = null, string password = null, WebinarSettings settings = null, IDictionary <string, string> trackingFields = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("topic", topic); data.AddPropertyIfValue("agenda", agenda); data.AddPropertyIfValue("password", password); data.AddPropertyIfValue("start_time", start?.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")); data.AddPropertyIfValue("duration", duration); data.AddPropertyIfValue("recurrence", recurrence); if (start.HasValue) { data.Add("timezone", "UTC"); } data.AddPropertyIfValue("settings", settings); data.AddPropertyIfValue("tracking_fields", trackingFields?.Select(tf => new JObject() { { "field", tf.Key }, { "value", tf.Value } })); var result = await _client .PatchAsync($"webinars/{webinarId}") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsMessage() .ConfigureAwait(false); if (result.StatusCode == System.Net.HttpStatusCode.OK) { // Zoom returns an HTTP 200 message when there is no webinar subscription and instead returns a 204 after a successful update throw new NotSupportedException("Webinar subscription plan is missing. Enable webinar for this user once the subscription is added"); } }
/// <summary> /// Update an existing suppression group. /// </summary> /// <param name="groupId">The group identifier.</param> /// <param name="name">The name of the new suppression group</param> /// <param name="description">A description of the suppression group</param> /// <param name="onBehalfOf">The user to impersonate</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns> /// The <see cref="SuppressionGroup" />. /// </returns> public Task <SuppressionGroup> UpdateAsync(long groupId, Parameter <string> name = default(Parameter <string>), Parameter <string> description = default(Parameter <string>), string onBehalfOf = null, CancellationToken cancellationToken = default(CancellationToken)) { var data = new JObject(); data.AddPropertyIfValue("name", name.Value); data.AddPropertyIfValue("description", description); return(_client .PatchAsync($"{_endpoint}/{groupId}") .OnBehalfOf(onBehalfOf) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <SuppressionGroup>()); }
/// <summary> /// Searches for contacts matching the specified conditions. /// </summary> /// <param name="conditions">The conditions.</param> /// <param name="listId">The list identifier.</param> /// <param name="onBehalfOf">The user to impersonate.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// An array of <see cref="Contact" />. /// </returns> public Task <Models.Legacy.Contact[]> SearchAsync(IEnumerable <Models.Legacy.SearchCondition> conditions, long?listId = null, string onBehalfOf = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("list_id", listId); data.AddPropertyIfValue("conditions", conditions); return(_client .PostAsync($"{_endpoint}/search") .OnBehalfOf(onBehalfOf) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <Models.Legacy.Contact[]>("recipients")); }
/// <summary> /// Request all contacts to be exported. /// /// Use the "job id" returned by this method with the CheckExportJobStatusAsync /// method to verify if the export job is completed. /// </summary> /// <param name="fileType">File type for export file. Choose from json or csv.</param> /// <param name="listIds">Ids of the contact lists you want to export.</param> /// <param name="segmentIds">Ids of the contact segments you want to export.</param> /// <param name="maxFileSize">The maximum size of an export file in MB. Note that when this option is specified, multiple output files will be returned from the export.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The job id. /// </returns> public Task <string> ExportAsync(FileType fileType = FileType.Csv, IEnumerable <string> listIds = null, IEnumerable <string> segmentIds = null, Parameter <long> maxFileSize = default, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("list_ids", listIds); data.AddPropertyIfValue("segment_ids", segmentIds); data.AddPropertyIfValue("file_type", fileType); data.AddPropertyIfValue("max_file_size", maxFileSize); return(_client .PostAsync($"{_endpoint}/exports") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <string>("id")); }
/// <summary> /// Add a registrant to a meeting. /// </summary> /// <param name="meetingId">The meeting ID.</param> /// <param name="email">A valid email address.</param> /// <param name="firstName">User's first name.</param> /// <param name="lastName">User's last name.</param> /// <param name="occurrenceId">The meeting occurrence id.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// A <see cref="Registrant" />. /// </returns> public Task <Registrant> AddRegistrantAsync(long meetingId, string email, string firstName, string lastName, string occurrenceId = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("email", email); data.AddPropertyIfValue("first_name", firstName); data.AddPropertyIfValue("last_name", lastName); return(_client .PostAsync($"meetings/{meetingId}/registrants") .WithArgument("occurence_id", occurrenceId) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsObject <Registrant>()); }
/// <summary> /// Notify Zoom that you comply with the policy which requires you to handle user's /// data in accordance to the user's preference after the user uninstalls your app. /// </summary> /// <param name="userId">The Zoom user's id who uninstalled your app.</param> /// <param name="accountId">The account Id.</param> /// <param name="deauthorizationEventReceived">This object represents the payload of the webhook event sent by Zoom in your Deauthorization Endpoint Url after a user uninstalls your app. The values of the parameters in this object should be the same as that of the deauthorization event that you receive.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The async task. /// </returns> public Task NotifyAsync(string userId, long accountId, AppDeauthorizedEvent deauthorizationEventReceived, CancellationToken cancellationToken = default) { // Prepare the request (but do not dispatch it yet) var request = _client .PostAsync("oauth/data/compliance") .WithCancellationToken(cancellationToken); // Figure out the client id and secret for authentication purposes var tokenHandler = (ITokenHandler)request.Filters.Single(f => f.GetType().IsAssignableFrom(typeof(ITokenHandler))); var secret = string.Empty; var clientId = string.Empty; switch (tokenHandler.ConnectionInfo) { case OAuthConnectionInfo oauthConnectionInfo: secret = oauthConnectionInfo.ClientSecret; clientId = oauthConnectionInfo.ClientId; break; case JwtConnectionInfo jwtConnectionInfo: throw new Exception($"The DataCompliance resource cannot be use with a Jwt connection."); default: throw new Exception($"Unable to determine the connection secret and cient Id. {tokenHandler.ConnectionInfo.GetType()} is an unknown connection type."); } // Prepare the payload var data = new JObject(); data.AddPropertyIfValue("client_id", clientId); data.AddPropertyIfValue("user_id", userId); data.AddPropertyIfValue("account_id", accountId); data.AddPropertyIfValue("deauthorization_event_received", deauthorizationEventReceived); data.AddPropertyIfValue("compliance_completed", "true"); // This endpoint relies on clientId+secret for authentication. It does not need tokens. request.Filters.Remove <OAuthTokenHandler>(); request.Filters.Remove <JwtTokenHandler>(); // Authenticate using clientId+secret and also specify the payload request = request .WithBasicAuthentication(clientId, secret) .WithJsonBody(data); // Return the async task return(request .AsMessage()); }
/// <summary> /// Update a Sub Account's options under the Master Account. /// </summary> /// <param name="accountId">The account Id.</param> /// <param name="useSharedVirtualRoomConnectors">Enable/disable the option for a sub account to use shared Virtual Room Connector(s).</param> /// <param name="roomConnectorsIpAddresses">The IP addresses of the Room Connectors that you would like to share with the sub account.</param> /// <param name="useSharedMeetingConnectors">Enable/disable the option for a sub account to use shared Meeting Connector(s).</param> /// <param name="meetingConnectorsIpAddresses">The IP addresses of the Meeting Connectors that you would like to share with the sub account.</param> /// <param name="payMode">Payee.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The async task. /// </returns> public Task UpdateOptionsAsync(long accountId, bool?useSharedVirtualRoomConnectors = null, IEnumerable <string> roomConnectorsIpAddresses = null, bool?useSharedMeetingConnectors = null, IEnumerable <string> meetingConnectorsIpAddresses = null, PayMode?payMode = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("share_rc", useSharedVirtualRoomConnectors); data.AddPropertyIfValue("room_connectors", roomConnectorsIpAddresses, ipAddresses => JToken.Parse(string.Join(",", ipAddresses))); data.AddPropertyIfValue("share_mc", useSharedMeetingConnectors); data.AddPropertyIfValue("meeting_connectors", meetingConnectorsIpAddresses, ipAddresses => JToken.Parse(string.Join(",", ipAddresses))); data.AddPropertyIfValue("pay_mode", payMode); return(_client .PatchAsync($"accounts/{accountId}/options") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsMessage()); }
/// <summary> /// Update a segment. /// </summary> /// <param name="segmentId">The segment identifier.</param> /// <param name="name">The name.</param> /// <param name="filterConditions">The query.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The <see cref="Segment" />. /// </returns> public Task <Segment> UpdateAsync(string segmentId, Parameter <string> name = default, Parameter <IEnumerable <KeyValuePair <SearchLogicalOperator, IEnumerable <SearchCriteria <ContactsFilterField> > > > > filterConditions = default, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("name", name); if (filterConditions.HasValue) { data.AddPropertyIfValue("query_dsl", ToQueryDsl(filterConditions.Value)); } return(_client .PatchAsync($"{_endpoint}/{segmentId}") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <Segment>()); }
private static JObject CreateJObject( Parameter <int> id = default, Parameter <string> username = default, Parameter <string> password = default, Parameter <string> email = default, Parameter <IEnumerable <string> > ips = default) { var result = new JObject(); result.AddPropertyIfValue("id", id); result.AddPropertyIfValue("username", username); result.AddPropertyIfValue("email", email); result.AddPropertyIfValue("password", password); result.AddPropertyIfValue("ips", ips); return(result); }
/// <summary> /// Update the details of a meeting occurence. /// </summary> /// <param name="meetingId">The meeting ID.</param> /// <param name="occurrenceId">The meeting occurrence id.</param> /// <param name="agenda">Meeting description.</param> /// <param name="start">Meeting start time.</param> /// <param name="duration">Meeting duration (minutes).</param> /// <param name="timeZone">The time zone for start time.</param> /// <param name="settings">Meeting settings.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The async task. /// </returns> public Task UpdateMeetingOccurrenceAsync(long meetingId, string occurrenceId, string agenda = null, DateTime?start = null, int?duration = null, TimeZones?timeZone = null, MeetingSettings settings = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("agenda", agenda); data.AddPropertyIfValue("start_time", start.ToZoomFormat(timeZone)); data.AddPropertyIfValue("duration", duration); data.AddPropertyIfEnumValue("timezone", timeZone); data.AddPropertyIfValue("settings", settings); return(_client .PatchAsync($"meetings/{meetingId}") .WithArgument("occurrence_id", occurrenceId) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsMessage()); }
/// <summary> /// Update a segment. /// </summary> /// <param name="segmentId">The segment identifier.</param> /// <param name="name">The name.</param> /// <param name="listId">The list identifier.</param> /// <param name="conditions">The conditions.</param> /// <param name="onBehalfOf">The user to impersonate.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The <see cref="Models.Legacy.Segment" />. /// </returns> public Task <Models.Legacy.Segment> UpdateAsync(long segmentId, string name = null, long?listId = null, IEnumerable <Models.Legacy.SearchCondition> conditions = null, string onBehalfOf = null, CancellationToken cancellationToken = default) { conditions = conditions ?? Enumerable.Empty <Models.Legacy.SearchCondition>(); var data = new JObject(); data.AddPropertyIfValue("name", name); data.AddPropertyIfValue("list_id", listId); data.AddPropertyIfValue("conditions", conditions); return(_client .PatchAsync($"{_endpoint}/{segmentId}") .OnBehalfOf(onBehalfOf) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <Models.Legacy.Segment>()); }
/// <summary> /// Update a template version. /// </summary> /// <param name="templateId">The template identifier.</param> /// <param name="versionId">The version identifier.</param> /// <param name="name">The name.</param> /// <param name="subject">The subject.</param> /// <param name="htmlContent">Content of the HTML.</param> /// <param name="textContent">Content of the text.</param> /// <param name="isActive">The is active.</param> /// <param name="onBehalfOf">The user to impersonate</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The <see cref="TemplateVersion" />. /// </returns> public Task <TemplateVersion> UpdateVersionAsync(string templateId, string versionId, string name = null, string subject = null, string htmlContent = null, string textContent = null, bool?isActive = null, string onBehalfOf = null, CancellationToken cancellationToken = default(CancellationToken)) { var data = new JObject(); data.AddPropertyIfValue("name", name); data.AddPropertyIfValue("subject", subject); data.AddPropertyIfValue("html_content", htmlContent); data.AddPropertyIfValue("plain_content", textContent); data.AddPropertyIfValue("active", isActive.HasValue ? (isActive.Value ? 1 : 0) : (int?)null); return(_client .PatchAsync($"{_endpoint}/{templateId}/versions/{versionId}") .OnBehalfOf(onBehalfOf) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <TemplateVersion>()); }
private Task UpdateMessageAsync(string messageId, string userId, string recipientEmail, string channelId, string message, IEnumerable <ChatMention> mentions, CancellationToken cancellationToken) { Debug.Assert(recipientEmail != null || channelId != null, "You must provide either recipientEmail or channelId"); Debug.Assert(recipientEmail == null || channelId == null, "You can't provide both recipientEmail and channelId"); var data = new JObject(); data.AddPropertyIfValue("message", message); data.AddPropertyIfValue("to_contact", recipientEmail); data.AddPropertyIfValue("to_channel", channelId); data.AddPropertyIfValue("at_items", mentions); return(_client .PutAsync($"chat/users/{userId}/messages/{messageId}") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsMessage()); }
/// <summary> /// Creates a user. /// </summary> /// <param name="email">The email address.</param> /// <param name="firstName">First name.</param> /// <param name="lastName">Last name.</param> /// <param name="type">The type of user.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The new user. /// </returns> /// <remarks> /// User will get an email sent from Zoom. There is a confirmation link in this email. /// The user will then need to use the link to activate their Zoom account. /// The user can then set or change their password. /// </remarks> public Task <User> CreateAsync(string email, string firstName = null, string lastName = null, UserType type = UserType.Basic, CancellationToken cancellationToken = default) { var data = new JObject() { { "action", "create" } }; data.AddPropertyIfValue("user_info/email", email); data.AddPropertyIfEnumValue("user_info/type", type); data.AddPropertyIfValue("user_info/first_name", firstName); data.AddPropertyIfValue("user_info/last_name", lastName); return(_client .PostAsync($"users") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsObject <User>()); }
/// <summary> /// Creates a user. /// </summary> /// <param name="email">The email address.</param> /// <param name="firstName">First name.</param> /// <param name="lastName">Last name.</param> /// <param name="password">User password. Only used when createType is <see cref="UserCreateType.Auto"/>.</param> /// <param name="type">The type of user.</param> /// <param name="createType">Specify how to create the user.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The new user. /// </returns> public Task <User> CreateAsync(string email, string firstName = null, string lastName = null, string password = null, UserType type = UserType.Basic, UserCreateType createType = UserCreateType.Normal, CancellationToken cancellationToken = default) { var data = new JObject() { { "action", JToken.Parse(JsonConvert.SerializeObject(createType)).ToString() } }; data.AddPropertyIfValue("user_info/email", email); data.AddPropertyIfEnumValue("user_info/type", type); data.AddPropertyIfValue("user_info/first_name", firstName); data.AddPropertyIfValue("user_info/last_name", lastName); data.AddPropertyIfValue("user_info/password", password); return(_client .PostAsync("users") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsObject <User>()); }
/// <summary> /// Add or Update multiple contacts. /// </summary> /// <param name="contacts">The contacts.</param> /// <param name="listIds">The identifiers of the lists where the contacts will be added to.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The job id. /// </returns> /// <exception cref="SendGridException">Thrown when an exception occurred while adding or updating the contact.</exception> public Task <string> UpsertAsync(IEnumerable <Contact> contacts, IEnumerable <string> listIds, CancellationToken cancellationToken = default) { var contactsJObject = new JArray(); foreach (var contact in contacts) { contactsJObject.Add(ConvertToJObject(contact)); } var data = new JObject(); data.AddPropertyIfValue("list_ids", listIds); data.AddPropertyIfValue("contacts", contactsJObject); return(_client .PutAsync(_endpoint) .WithJsonBody(data, true) .WithCancellationToken(cancellationToken) .AsSendGridObject <string>("job_id")); }
/// <summary> /// Update the details of a meeting occurence. /// </summary> /// <param name="meetingId">The meeting ID.</param> /// <param name="occurrenceId">The meeting occurrence id.</param> /// <param name="agenda">Meeting description.</param> /// <param name="start">Meeting start time.</param> /// <param name="duration">Meeting duration (minutes).</param> /// <param name="settings">Meeting settings.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The async task. /// </returns> public Task UpdateMeetingOccurrenceAsync(long meetingId, string occurrenceId, string agenda = null, DateTime?start = null, int?duration = null, MeetingSettings settings = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("agenda", agenda); data.AddPropertyIfValue("start_time", start?.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")); data.AddPropertyIfValue("duration", duration); if (start.HasValue) { data.Add("timezone", "UTC"); } data.AddPropertyIfValue("settings", settings); return(_client .PatchAsync($"meetings/{meetingId}") .WithArgument("occurrence_id", occurrenceId) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsMessage()); }
/// <summary> /// Create a sub account under the master account. /// </summary> /// <param name="firstName">User's first name.</param> /// <param name="lastName">User's last name.</param> /// <param name="email">User's email address.</param> /// <param name="password">User's password.</param> /// <param name="useSharedVirtualRoomConnectors">Enable/disable the option for a sub account to use shared Virtual Room Connector(s).</param> /// <param name="roomConnectorsIpAddresses">The IP addresses of the Room Connectors that you would like to share with the sub account.</param> /// <param name="useSharedMeetingConnectors">Enable/disable the option for a sub account to use shared Meeting Connector(s).</param> /// <param name="meetingConnectorsIpAddresses">The IP addresses of the Meeting Connectors that you would like to share with the sub account.</param> /// <param name="payMode">Payee.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// An array of <see cref="Account">accounts</see>. /// </returns> public Task <Account> CreateAsync(string firstName, string lastName, string email, string password, bool useSharedVirtualRoomConnectors = false, IEnumerable <string> roomConnectorsIpAddresses = null, bool useSharedMeetingConnectors = false, IEnumerable <string> meetingConnectorsIpAddresses = null, PayMode payMode = PayMode.Master, CancellationToken cancellationToken = default) { var data = new JObject() { { "first_name", firstName }, { "last_name", lastName }, { "email", email }, { "password", password } }; data.AddPropertyIfValue("options/share_rc", useSharedVirtualRoomConnectors); data.AddPropertyIfValue("options/room_connectors", roomConnectorsIpAddresses, ipAddresses => JToken.Parse(string.Join(",", ipAddresses))); data.AddPropertyIfValue("options/share_mc", useSharedMeetingConnectors); data.AddPropertyIfValue("options/meeting_connectors", meetingConnectorsIpAddresses, ipAddresses => JToken.Parse(string.Join(",", ipAddresses))); data.AddPropertyIfValue("options/pay_mode", payMode); return(_client .PostAsync($"accounts") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsObject <Account>()); }
/// <summary> /// Request all contacts to be exported. /// /// Use the "job id" returned by this method with the CheckExportJobStatusAsync /// method to verify if the export job is completed. /// </summary> /// <param name="stream">The stream containing the data to import.</param> /// <param name="fileType">File type for export file. Choose from json or csv.</param> /// <param name="fieldsMapping">List of field_definition IDs to map the uploaded CSV columns to. For example, [null, "w1", "_rf1"] means to skip Col[0], map Col[1] => CustomField w1, map Col[2] => ReservedField _rf1.</param> /// <param name="listIds">Ids of the contact lists you want to export.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The job id. /// </returns> public async Task <string> ImportFromStreamAsync(Stream stream, FileType fileType, IEnumerable <string> fieldsMapping = null, IEnumerable <string> listIds = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("list_ids", listIds); data.AddPropertyIfValue("file_type", fileType); data.AddPropertyIfValue("field_mappings", fieldsMapping); var importRequest = await _client .PutAsync($"{_endpoint}/imports") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsRawJsonObject() .ConfigureAwait(false); var importJobId = importRequest["id"].Value <string>(); var uploadUrl = importRequest["upload_url"].Value <string>(); var uploadHeaders = importRequest["upload_headers"].Value <KeyValuePair <string, string>[]>(); var request = new HttpRequestMessage(HttpMethod.Post, uploadUrl) { Content = new StreamContent(stream) }; request.Headers.Clear(); foreach (var header in uploadHeaders) { request.Headers.Add(header.Key, header.Value); } using (var client = new HttpClient()) { await client.SendAsync(request).ConfigureAwait(false); } return(importJobId); }
/// <summary> /// Validate an email address. /// </summary> /// <param name="emailAddress">The email address to validate.</param> /// <param name="source">One word classifier for this validation. For example: "signup".</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The <see cref="EmailValidationResult" />. /// </returns> public Task <EmailValidationResult> ValidateAsync(string emailAddress, string source = null, CancellationToken cancellationToken = default) { var data = new JObject { { "email", emailAddress } }; data.AddPropertyIfValue("source", source); return(_client .PostAsync(_endpoint) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <EmailValidationResult>("result")); }
/// <summary> /// Create a segment. /// </summary> /// <param name="name">The name.</param> /// <param name="filterConditions">The query.</param> /// <param name="listId">The id of the list if this segment is a child of a list. This implies the query is rewritten as (${query_dsl}) AND CONTAINS(list_ids, ${parent_list_id}).</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The <see cref="Segment" />. /// </returns> public Task <Segment> CreateAsync(string name, IEnumerable <KeyValuePair <SearchLogicalOperator, IEnumerable <SearchCriteria <ContactsFilterField> > > > filterConditions, string listId = null, CancellationToken cancellationToken = default) { var data = new JObject { { "name", name }, { "query_dsl", ToQueryDsl(filterConditions) } }; data.AddPropertyIfValue("parent_list_id", listId); return(_client .PostAsync(_endpoint) .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsSendGridObject <Segment>()); }
/// <summary> /// Creates a recurring meeting for a user. /// </summary> /// <param name="userId">The user Id or email address.</param> /// <param name="topic">Meeting topic.</param> /// <param name="agenda">Meeting description.</param> /// <param name="start">Meeting start time. If omitted, a 'Recurring meeting with no fixed time' will be created.</param> /// <param name="duration">Meeting duration (minutes).</param> /// <param name="recurrence">Recurrence information.</param> /// <param name="password">Password to join the meeting. Password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters.</param> /// <param name="settings">Meeting settings.</param> /// <param name="trackingFields">Tracking fields.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The new meeting. /// </returns> /// <exception cref="System.Exception">Thrown when an exception occured while creating the meeting.</exception> public Task <RecurringMeeting> CreateRecurringMeetingAsync( string userId, string topic, string agenda, DateTime?start, int duration, RecurrenceInfo recurrence, string password = null, MeetingSettings settings = null, IDictionary <string, string> trackingFields = null, CancellationToken cancellationToken = default) { var data = new JObject() { // 3 = Recurring with no fixed time // 8 = Recurring with fixed time { "type", start.HasValue ? 8 : 3 } }; data.AddPropertyIfValue("topic", topic); data.AddPropertyIfValue("password", password); data.AddPropertyIfValue("agenda", agenda); data.AddPropertyIfValue("start_time", start?.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")); data.AddPropertyIfValue("duration", duration); data.AddPropertyIfValue("recurrence", recurrence); data.AddPropertyIfValue("timezone", "UTC"); data.AddPropertyIfValue("settings", settings); data.AddPropertyIfValue("tracking_fields", trackingFields?.Select(tf => new JObject() { { "field", tf.Key }, { "value", tf.Value } })); return(_client .PostAsync($"users/{userId}/meetings") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsObject <RecurringMeeting>()); }
private static JObject ConvertToJObject( Parameter <string> email, Parameter <string> firstName, Parameter <string> lastName, Parameter <IEnumerable <Models.Legacy.Field> > customFields) { var result = new JObject(); result.AddPropertyIfValue("email", email); result.AddPropertyIfValue("first_name", firstName); result.AddPropertyIfValue("last_name", lastName); if (customFields.HasValue && customFields.Value != null) { foreach (var customField in customFields.Value.OfType <Models.Legacy.Field <string> >()) { result.AddPropertyIfValue(customField.Name, customField.Value); } foreach (var customField in customFields.Value.OfType <Models.Legacy.Field <long> >()) { result.AddPropertyIfValue(customField.Name, customField.Value); } foreach (var customField in customFields.Value.OfType <Models.Legacy.Field <long?> >()) { result.AddPropertyIfValue(customField.Name, customField.Value); } foreach (var customField in customFields.Value.OfType <Models.Legacy.Field <DateTime> >()) { result.AddPropertyIfValue(customField.Name, customField.Value.ToUnixTime()); } foreach (var customField in customFields.Value.OfType <Models.Legacy.Field <DateTime?> >()) { result.AddPropertyIfValue(customField.Name, customField.Value?.ToUnixTime()); } } return(result); }
private static JObject CreateJObject( Parameter <string> nickname, Parameter <MailAddress> from, Parameter <MailAddress> replyTo, Parameter <string> address1, Parameter <string> address2, Parameter <string> city, Parameter <string> state, Parameter <string> zip, Parameter <string> country) { var result = new JObject(); result.AddPropertyIfValue("nickname", nickname); result.AddPropertyIfValue("from", from); result.AddPropertyIfValue("reply_to", from); result.AddPropertyIfValue("address", address1); result.AddPropertyIfValue("address2", address2); result.AddPropertyIfValue("city", city); result.AddPropertyIfValue("state", state); result.AddPropertyIfValue("zip", zip); result.AddPropertyIfValue("country", country); return(result); }
/// <summary> /// Update the details of a recurring meeting. /// </summary> /// <param name="meetingId">The meeting ID.</param> /// <param name="userId">The user Id or email address.</param> /// <param name="topic">Meeting topic.</param> /// <param name="agenda">Meeting description.</param> /// <param name="start">Meeting start time. If omitted, a 'Recurring meeting with no fixed time' will be created.</param> /// <param name="duration">Meeting duration (minutes).</param> /// <param name="timeZone">The time zone for start time.</param> /// <param name="recurrence">Recurrence information.</param> /// <param name="password">Password to join the meeting. Password may only contain the following characters: [a-z A-Z 0-9 @ - _ *]. Max of 10 characters.</param> /// <param name="settings">Meeting settings.</param> /// <param name="trackingFields">Tracking fields.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The async task. /// </returns> public Task UpdateRecurringMeetingAsync(long meetingId, string userId = null, string topic = null, string agenda = null, DateTime?start = null, int?duration = null, TimeZones?timeZone = null, RecurrenceInfo recurrence = null, string password = null, MeetingSettings settings = null, IDictionary <string, string> trackingFields = null, CancellationToken cancellationToken = default) { var data = new JObject(); data.AddPropertyIfValue("schedule_for", userId); data.AddPropertyIfValue("topic", topic); data.AddPropertyIfValue("password", password); data.AddPropertyIfValue("agenda", agenda); data.AddPropertyIfValue("start_time", start.ToZoomFormat(timeZone)); data.AddPropertyIfValue("duration", duration); data.AddPropertyIfValue("recurrence", recurrence); data.AddPropertyIfEnumValue("timezone", timeZone); data.AddPropertyIfValue("settings", settings); data.AddPropertyIfValue("tracking_fields", trackingFields?.Select(tf => new JObject() { { "field", tf.Key }, { "value", tf.Value } })); return(_client .PatchAsync($"meetings/{meetingId}") .WithJsonBody(data) .WithCancellationToken(cancellationToken) .AsMessage()); }