Example for creating an 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":"2015-05-02","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();
}
I am able to create a single opportunity using above code. But when i try to create multiple record using below "newrecord.json" file getting error.
Example request body for multiple record newrecord.json file :
[{"Name":"Opp1","CloseDate":"2015-05-02","StageName":"Stage1","Probability":"10","Amount":"1500"},{"Name":"Opp2","CloseDate":"2015-02-03","StageName":"Stage2","Probability":"5","Amount":"2000"}]
Error in .net Code : 400 bad request
Error in Workbench : errorCode: METHOD_NOT_ALLOWED message: HTTP Method 'POST' not allowed. Allowed are HEAD,GET