简体   繁体   中英

Salesforce Rest API patch operation - Bad Request

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)
    {
        SetupHttpClient();

        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))
        {

新秀错误-补丁中有一个我不允许更新的字段,因为我正在处理同一个对象,并根据对象是否已经存在而在POST和PATCH之间切换,所以我不知道该字段级别限制。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM