Example for creating Opportunity

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

Example request body newrecord.json file


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/"));
    request.Method = "POST";
    using (var requestWriter = new StreamWriter(request.GetRequestStream()))
    var response = request.GetResponse();

Getting Error 400 Bad Request in "request.GetResponse()". I am able to create Account using same code. I don't Know what wrongs with Opportunity.

Error Details :

System.Net.WebException was unhandled by user code
  Message=The remote server returned an error: (400) Bad Request.
       at System.Net.HttpWebRequest.GetResponse()
       at WebApplication2.About.CreateSampleOpportunity() in D:\Fenil\DotNetProjects\WebApplication1\WebApplication2\About.aspx.cs:line 381
       at WebApplication2.About.Page_Load(Object sender, EventArgs e) in D:\Fenil\DotNetProjects\WebApplication1\WebApplication2\About.aspx.cs:line 41
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  • 1
    The body of the response will have more details about why the request is invalid. At a guess, your date format is wrong, it should be 2015-03-02
    – superfell
    Mar 2, 2015 at 16:43
  • Thanks for reply sir. I have tried with all date format, With Probability, Without Probability. I think issue is with "StageName" or "Probability". Both are Compalasary Filelds and one is numeric and other one is Picklist(Dropdown). Mar 3, 2015 at 5:10
  • You need to capture and examine the response body, IIRC, its available as a property on the thrown exception.
    – superfell
    Mar 3, 2015 at 15:33

1 Answer 1


The problem was in the date format."CloseDate":"3/2/2015"

Right date format : "CloseDate":"2015-03-02"

{ "Name":"FFNEw","CloseDate":"2015-03-02","StageName":"Prospecting","Probability":10 }

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.