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
{
"Name":"FFNEw","CloseDate":"3/2/2015","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/"));
request.Method = "POST";
using (var requestWriter = new StreamWriter(request.GetRequestStream()))
{
requestWriter.Write(json);
requestWriter.Flush();
requestWriter.Close();
}
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
HResult=-2146233079
Message=The remote server returned an error: (400) Bad Request.
Source=System
StackTrace:
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)
InnerException: