public async Task <PhoneContactabilitiesResponse> GetPhoneContactability(PhoneContactabilitiesRequest request) { var reqMessage = new HttpRequestMessage(HttpMethod.Post, "api/PhoneContactabilities"); reqMessage.Content = new StringContent(JsonConvert.SerializeObject(request, new StringEnumConverter())); reqMessage.Content.Headers.ContentType = new Headers.MediaTypeHeaderValue("application/json"); return(await MakeRequestAndParseResponse <PhoneContactabilitiesResponse>(reqMessage)); }
/// <summary> /// Given a phone number, some optional name fields and a particular topic id, check if those contact values /// can be contacted by the topic id. /// This end point is pessimistic, in that if CPM does not know about the contact value or if the contact value does not know about the topic, /// the "CanContact" value will always return false. /// </summary> /// <param name="phoneNumber">The phone number to check. </param> /// <param name="firstName">Optional, First Name. </param> /// <param name="lastName">Optional, Last Name".</param> /// <param name="topicId">The topic id".</param> /// <returns></returns> private static async Task GetPhoneContactabilities(string phoneNumber, string firstName, string lastName, Guid topicId) { ContactName name = new ContactName() { FirstName = firstName, LastName = lastName }; PhoneContactIdentity identity = new PhoneContactIdentity() { PhoneNumber = phoneNumber, Name = name }; PhoneContactabilitiesRequest request = new PhoneContactabilitiesRequest() { Identity = identity, TargetedTopicId = topicId }; using (HttpClient client = await CPMClientGenerator.CreateHttpClientAsync()) { HttpResponseMessage response = await client.PostAsJsonAsync("/api/PhoneContactabilities", request); if (response.IsSuccessStatusCode) { PhoneContactabilitiesResponse result = await response.Content.ReadAsAsync <PhoneContactabilitiesResponse>(); Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); } else { Console.WriteLine(await response.Content.ReadAsStringAsync()); } } }
/// <summary> /// Given a phone number, some optional name fields and a particular topic id, check if those contact values /// can be contacted by the topic id. /// This end point is pessimistic, in that if CPM does not know about the contact value or if the contact value does not know about the topic, /// the "CanContact" value will always return false. /// </summary> private static void GetPhoneContactabilities() { ContactName name = new ContactName() { FirstName = "John", LastName = "Doe" }; PhoneContactIdentity identity = new PhoneContactIdentity() { PhoneNumber = "+14256668888", //The phone number should follow the E.164 standard Name = name }; PhoneContactabilitiesRequest request = new PhoneContactabilitiesRequest() { Identity = identity, TargetedTopicId = testTopicId }; PhoneContactabilitiesResponse result = cpmClient.GetPhoneContactability(request).Result; Console.WriteLine(JsonConvert.SerializeObject(result)); }