Hi,
I have set a duplicate detection rule for Contact entity - for fields firstname and last name , exact match.
- This is working fine if I manually create a Contact record.
But i need to detect duplicates from C# code in which i am trying to create a Contact record using WebApi.
Can any one help me by suggesting me how to call this WebApi- MSCRM.SupressDuplicateDetection
private static async Task CreateRecord(HttpClient httpClient)
{
httpClient.DefaultRequestHeaders.Add("MSCRM.SupressDuplicateDetection", "false");
var contact1 = new JObject
{
{ "firstname", "" },
{ "lastname", "" }
};
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "contacts")
{
Content = new StringContent(contact1.ToString(), Encoding.UTF8, "application/json")
};
HttpResponseMessage response = await httpClient.SendAsync(request);
httpClient.DefaultRequestHeaders.Add("MSCRM.SupressDuplicateDetection", "false");
if (response.StatusCode == HttpStatusCode.NoContent)
{
Console.WriteLine("Succeeded");
}
else
{
Console.WriteLine("Operation failed: {0}", response.ReasonPhrase);
}
}
Tried this but didn't work.
Thanks in advance.