I'm pretty new to the Salesforce REST API, and where do I find documentation or a resource on how to create a case in Salesforce using their API?
-
Do you want to create a REST API Web Service that will create the case or you want to use the TOOLING API in order to create a case directly in Salesforce?– Boris BachovskiCommented Aug 12, 2014 at 4:30
-
@Bachovski I want to create a case via their REST API.– Peter IndiolaCommented Aug 12, 2014 at 4:45
-
Apologies I meant the salesforce REST API not tooling :) @AtulRajguru9 has already provided a nice answer with some examples that you'll be able to work out from.– Boris BachovskiCommented Aug 12, 2014 at 4:57
-
gotcha. Sorry but off topic I notice in the document a instance_name what does it mean? I saw this in the documentation curl instance_name.salesforce.com/services/data/v20.0 -H 'Authorization: Bearer access_token'– Peter IndiolaCommented Aug 12, 2014 at 5:06
-
Instance name is the server name or the subdomain of your salesforce org (when you log in, in the URL you see ap1., eu0., cs4. etc.).– Boris BachovskiCommented Aug 12, 2014 at 5:16
Add a comment
|
2 Answers
Here is sample code for you:
https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_REST_API
Here is PHP code for your reference:
function create_account($name, $instance_url, $access_token) {
$url = "$instance_url/services/data/v20.0/sobjects/Account/";
$content = json_encode(array("Name" => $name));
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Authorization: OAuth $access_token",
"Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
echo "HTTP status $status creating account<br/><br/>";
curl_close($curl);
$response = json_decode($json_response, true);
$id = $response["id"];
echo "New record id $id<br/><br/>";
return $id;
}