+ Start a Discussion
Fenil Suthar 007Fenil Suthar 007 

Update Opportunity Using rest API; Error : 400 bad request in response

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()".

Anupam RastogiAnupam Rastogi
Hi Fenil,

To start with, I have done similar scenario. However I had Salesforce applications as both the calling and receiving ends. And I observed that though Salesforce API supports PATCH method but when we use it programatically it errors. The error is "Invalid HTTP method: PATCH".

So my first question is, did you check logs for your calling application? Are you getting any errors while calling Salesforce using the PATCH method.

Anyways, you can try using the below modified end point. It should work for you as it did for me.


Also remember to change the calling method to post. So your code should look like the below - 
var request = (HttpWebRequest)(HttpWebRequest.Create(token.instance_url + "/services/data/v20.0/sobjects/Opportunity/0AASSFGSEID?_HttpMethod=PATCH"));
request.Method = "POST";


If the reply is helpful and solves your problem then please mark it as best.

king s 8king s 8
Hi Anupam Rastogi,

your ans is So help full for me thank you so much...........