We sync our organisations employees list to the External Contacts list. We run a sync on a daily basis. When an employee leaves, I'm trying to delete the external contact entry of that employee. However, I'm having issues. When I have 3 or more leavers on the same day, I seem to be able to delete the first and second. Deletion of the third fails.
Here is the delete function I'm using. I'm calling it from the Sync function when a leaver is identified and needs deleting:
private Object DeleteContact(String AccessToken, string ContactId)
{
rtLog.Text += "Deleting Step 1" + Environment.NewLine;
string url = "https://api.euw2.pure.cloud/api/v2/externalcontacts/contacts/" + ContactId;
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
rtLog.Text += "Deleting Step 2" + Environment.NewLine;
httpWebRequest.Method = "DELETE";
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("Authorization", "Bearer " + AccessToken);
rtLog.Text += "Deleting Step 3" + Environment.NewLine;
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
rtLog.Text += "Deleting Step 4" + Environment.NewLine;
var result = new
{
StatusCode = httpResponse.StatusCode,
StatusDescription = httpResponse.StatusDescription
};
rtLog.Text += "Deleting Step 5" + Environment.NewLine;
return result;
}
I've added some log comments to the code. When deleting the 1st and 2nd contact, the code runs though to step 5 and the contact is deleted. On the 3rd contact, the code gets as far as Step 3 and no further. No errors are returned. The code just stops at that stage.
Any help or guidance on this will be appreciated.