Example for creating Opportunity :

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Opportunity/0AASSFGSEID -H "Authorization: Bearer token" -H "Content-Type: application/json" -d @newrecord.json -X PATCH

Example request body newrecord.json file :

{ "Name":"FFNEw","CloseDate":"2015/02/04","StageName":"Prospecting","Probability":10 }

My ASP.net code :

using (WebClient client = new WebClient())
client.Headers.Add("Authorization", "Bearer " + token.access_token); client.Headers.Add("Content-Type", "application/json");
var request = (HttpWebRequest)(HttpWebRequest.Create(token.instance_url + "/services/data/v20.0/sobjects/Opportunity/0AASSFGSEID"));
request.Method = "PATCH";
using (var requestWriter = new StreamWriter(request.GetRequestStream()))
var response = request.GetResponse();

Getting Error 400 Bad Request in "request.GetResponse()".

  • Make sure your token has been url decoded first - in the past I've forgotten to urldecode the token and it contained a '!' character, which I posted back still encoded (causing it to get encoded twice) Apr 6, 2015 at 8:09

1 Answer 1

var request = (HttpWebRequest)(HttpWebRequest.Create(token.instance_url + "/services/data/v20.0/sobjects/Opportunity/0AASSFGSEID?_HttpMethod=PATCH"));

I have just added ?_HttpMethod=PATCH in request url and it's working for me..

  • That is how it is described in this guide Pages(49-50)
    – abhi
    Jan 12, 2016 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.