Salesforce Case integration via REST API

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?

Answer

Here is sample code for you:

https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_REST_API

http://www.salesforce.com/us/developer/docs/api_rest/index_Left.htm#CSHID=quickstart_code.htm|StartTopic=Content%2Fquickstart_code.htm|SkinName=webhelp

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;
}

Attribution
Source : Link , Question Author : Peter Indiola , Answer Author : AtulRajguru9

Leave a Comment