I'm trying to invoke a PATCH operation on our organization's Salesforce API. The url is correct (format - https://xxxx.salesforce.com/services/data/v43.0/sobjects/Classification__c/objectid?_HttpMethod=PATCH) and so is the JSON content, though you possibly can't guage that from the code below.

public async Task PatchSalesforceObjectAsync(string objectToPost, string objectid, HttpContent content)

    using (_response = await _httpClient.PostAsync($"{_sfObjectPartialURL}{objectToPost}{objectid}?_HttpMethod=PATCH", content))
        if (_response.IsSuccessStatusCode)
            var x = _response.Content;

void SetupHttpClient()
    _httpClient = new HttpClient();
    _httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _sfAccesstoken);
    _httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
    _httpClient.BaseAddress = _baseURI;

Response - StatusCode:400, ReasonPhrase:Bad Request

I've made the exact same request through POSTMAN and it goes through fine, so I'm guessing that the issue lies with how I'm making the call in the .Net framework.

I've also tried using a HttpRequestMessage object and then call SendAsync on the HttpClient object, but that leads to the same result.

HttpRequestMessage message = new HttpRequestMessage()
        Method = new HttpMethod("PATCH"),
        RequestUri = new Uri(_baseURI, $"{_sfObjectPartialURL}{objectToPost}{objectid}"),
        Content = content,
    using (_response = await _httpClient.SendAsync(message))

1 Answer 1


Rookie Mistake - There was a field in the Patch that I'm not allowed to update and since I was dealing with the same object and switching between a POST and a PATCH based on whether the object already existed I was not aware of this field level restriction.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .