I'm writing a plug-in to send a PATCH request to the REST API whenever a new opportunity is created. But I keep getting the same error "400 Bad Request". However, I tested the URL in POSTMAN and it works fine. This is my code (the plug-in will call this method):
private async void MakeRequest(string requestUrl, ITracingService tracingService)
{
try
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(requestUrl);
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.TryAddWithoutValidation("Ocp-Apim-Subscription-Key", subscriptionKey);
HttpRequestMessage request = new HttpRequestMessage(new HttpMethod("PATCH"), "relativeAddress");
request.Content = new StringContent("{\"name\":\"John Doe\",\"path\":\"prescriptive-actions/status\",\"value\":\"Completed\",\"from\":\"New\"}", Encoding.UTF8, "application/json");
var task = client.SendAsync(request)
.ContinueWith(responseTask =>
{
tracingService.Trace("responseTask {0}", responseTask.Result);
});
task.Wait();
}
catch (Exception ex)
{
tracingService.Trace("PROSPluginNotifyPAO Error: {0}", ex.ToString());
throw;
}
}
*This post is locked for comments
I have the same question (0)