/// <summary> /// Patches an email contact point with a subscription to a topic. Will create a new email contact point if the email contact point does not exist. Cannot be used to mark an email contact point as inactive. /// </summary> /// <param name="emailAddress">The email address of the email contact point eg. [email protected]</param> /// <param name="countryName">Optional, the country of the email contact point</param> /// <param name="topicId">the identifier of the topic</param> /// <param name="state">The state the subscription should be in eg. OptInExplicit</param> /// <returns></returns> private static async Task PatchEmailContactPoint(string emailAddress, string countryName, Guid topicId, ContactPointTopicSettingState state) { EmailContactPoint emailContactPoint = new EmailContactPoint() { Email = emailAddress, Country = countryName }; emailContactPoint.TopicSettings.Add(new ContactPointTopicSetting { TopicId = topicId, CultureName = CultureInfo.CurrentCulture.ToString(), LastSourceSetDate = DateTime.UtcNow, OriginalSource = "SampleCPMProject", State = state }); using (HttpClient client = await CPMClientGenerator.CreateHttpClientAsync()) { HttpResponseMessage response = await client.PatchAsync("api/EmailContacts", emailContactPoint); if (response.IsSuccessStatusCode) { EmailContactPoint patched = await response.Content.ReadAsAsync <EmailContactPoint>(); Console.WriteLine(JsonConvert.SerializeObject(patched, Formatting.Indented)); } else { Console.WriteLine(await response.Content.ReadAsStringAsync()); } } }
/// <summary> /// Given an existing email address, looks up the email contact point and prints it out. /// </summary> private static void GetEmailContactPoint() { string emailAddress = "*****@*****.**"; EmailContactPoint result = cpmClient.GetEmailContactPoint(emailAddress).Result; Console.WriteLine(JsonConvert.SerializeObject(result)); }
public async Task <EmailContactPoint> PatchEmailContactPoint(EmailContactPoint contactToPatch) { var reqMessage = new HttpRequestMessage(new HttpMethod("PATCH"), "api/EmailContacts"); reqMessage.Content = new StringContent(JsonConvert.SerializeObject(contactToPatch, new StringEnumConverter())); reqMessage.Content.Headers.ContentType = new Headers.MediaTypeHeaderValue("application/json"); return(await MakeRequestAndParseResponse <EmailContactPoint>(reqMessage)); }
/// <summary> /// Patches an email contact point with a subscription to a topic. Will create a new email contact point if the email contact point does not exist. /// Cannot be used to mark an email contact point as inactive. /// </summary> private static void PatchEmailContactPoint() { EmailContactPoint emailContactPoint = new EmailContactPoint() { Email = "*****@*****.**", Country = "US" //Use only ISO 2 char country codes. Any other string will result in HTTP 400 }; emailContactPoint.TopicSettings.Add(new ContactPointTopicSetting { TopicId = testTopicId, //Topic ID for which this permission was collected CultureName = CultureInfo.CurrentCulture.ToString(), //Specify a culture supported by the topic. E.g en-US, fr-FR, fr-CA etc. Communication with the user will be based on this culture; LastSourceSetDate = DateTime.UtcNow, //The actual time at which this permission was collected. Could be in the past.. OriginalSource = "SampleCPMProject", //Name of this application that collected the consent. Saved for auditing purposes. State = ContactPointTopicSettingState.OptInExplicit //The permission }); EmailContactPoint updatedContactPoint = cpmClient.PatchEmailContactPoint(emailContactPoint).Result; Console.WriteLine(JsonConvert.SerializeObject(updatedContactPoint)); }
/// <summary> /// Given an existing email address, looks up the email contact point and prints it out. /// </summary> /// <param name="emailAddress">The email address of the email contact point eg. [email protected]</param> /// <returns></returns> private static async Task GetEmailContactPoint(string emailAddress) { using (HttpClient client = await CPMClientGenerator.CreateHttpClientAsync()) { HttpMethod get = new HttpMethod("GET"); HttpRequestMessage request = new HttpRequestMessage(get, "api/EmailContacts"); request.Headers.Add("x-ms-filter-email", emailAddress); request.Headers.Add("Accept", "application/json"); HttpResponseMessage response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { EmailContactPoint emailContactPoint = await response.Content.ReadAsAsync <EmailContactPoint>(); Console.WriteLine(JsonConvert.SerializeObject(emailContactPoint, Formatting.Indented)); } else { Console.WriteLine(await response.Content.ReadAsStringAsync()); } } }