Examples

1. Creating an opportunity record using php

<?php
function authenticate($username, $password)
{

$login = ["Username" => $username,

"password" => $password,
];

$url = sprintf("%s?%s", "https://www.cirrus-shield.net/RestApi/AuthToken", http_build_query($login));

$client = curl_init();

curl_setopt($client, CURLOPT_VERBOSE, true);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_URL, $url);

$response = curl_exec($client);
curl_close($client);

return $response;  

}
function createOpportunity($urlParams, $xmlData)
{

$url = sprintf("%s?%s", "http://www.cirrus-shield.net/RestApi/DataAction/Opportunity", http_build_query($urlParams));
$headers = array(

"Content-Type: application/x-www-form-urlencoded",
"charset=utf-8",
);

$client = curl_init();

curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_URL, $url);
curl_setopt($client, CURLOPT_HTTPHEADER, $headers);
curl_setopt($client, CURLOPT_POSTFIELDS, "=".$xmlData);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLINFO_HEADER_OUT, true);
curl_setopt ($client, CURLOPT_SSLVERSION, 6);

$response = curl_exec($client);
curl_close($client);

echo "<br><br> HTTP Response content = ";
print_r('<pre>');
var_dump($response);
print_r('</pre>');

echo "<br><br> POST content = ";

return $response;

}
$username = "mail@mail.com";
$password = "password";

$authToken = authenticate($username, $password);
$authToken = str_replace(""", "", $authToken);

if ($authToken != '')
{

$opportunityName = filter_input(INPUT_POST, 'Name', FILTER_SANITIZE_STRING);
$opportunityOwner = filter_input(INPUT_POST, 'Owner', FILTER_SANITIZE_STRING);
$xmlData =
"<Data>"

."<Opportunity>"

."<Id></Id>"
."<Name>Test3</Name>"
."<OwnerId>1385102248752711769</OwnerId>"

."</Opportunity>"

."</Data>";

$urlParams = ["authToken" => $authToken,

"action" => "insert",
"matchingFieldName" => "Id",
];

$createOpportunity = createOpportunity($urlParams,$xmlData);

} else {

echo "<br>Authentication Failed";

}
?>

2. Selecting a lead record using php

<!DOCTYPE html>
<html>

<head>

<meta charset="UTF-8">
<title>REST API Test - Select Lead</title>

</head>
<body>

<?php
function authenticate($username, $password)
{

$login = ["Username" => $username,

"password" => $password,
];

$url = sprintf("%s?%s", "http://cirrus-shield.net/RestApi/AuthToken", http_build_query($login));
$client = curl_init();

curl_setopt($client, CURLOPT_VERBOSE, true);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_URL, $url);

$response = curl_exec($client);
curl_close($client);
return $response;  

}
function SelectLead($authToken)
{

$selectparam = ["authToken" => $authToken,

"selectQuery" => "SELECT Email FROM Lead WHERE Id=1475450326663301794",
];

$url = sprintf("%s?%s", "http://cirrus-shield.net/RestApi/Query", http_build_query($selectparam));
$client = curl_init();

curl_setopt($client, CURLOPT_VERBOSE, true);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_URL, $url);

$response = curl_exec($client);
curl_close($client);

$array_data = json_decode($response, true);
print_r('<pre>');
var_dump($response);
print_r('</pre>');
return $response;

}

$username = "mail@mail.com";
$password = "password";

$authToken = authenticate($username, $password);
$authToken = str_replace(""", "", $authToken);

if ($authToken != '')

{

$selectLead = SelectLead($authToken);

} else {

echo "<br>Authentication Failed";

}?>

</body>

</html>

3. Get Your Organization Id

We can get our Organization Id using the Rest API by sending the following select query to the “Query” API Method: “SELECT Id FROM Organization”. This query will return one record which contains the Id of the Organization. Example of returned record (in json): “{“Data”:{“Organization”:[{“Id”:”1453301944234805898″}]}}”.

4. Get User Timezone

We can get the User Timezone using the Rest API by sending the following select query to the “Query” API Method: “SELECT DefaultTimeZoneSidKey FROM Organization”. This query will return one record which contains the User Timezone which is the same as the Organization Timezone. Example of returned record (in json): “{“Data”:{“Organization”:[{“DefaultTimeZoneSidKey”:”GMT”}]}}”.

<!DOCTYPE html><html>

<head>

<meta charset="UTF-8"><title>REST API Test - Select Lead</title>

</head><body>

<?phpfunction authenticate($username, $password){

$login = ["Username" => $username,

"password" => $password,];

$url = sprintf("%s?%s", "http://cirrus-shield.net/RestApi/AuthToken", http_build_query($login));$client = curl_init();

curl_setopt($client, CURLOPT_VERBOSE, true);curl_setopt($client, CURLOPT_RETURNTRANSFER, true);curl_setopt($client, CURLOPT_URL, $url);

$response = curl_exec($client);curl_close($client);return $response;  

}function SelectLead($authToken){

$selectparam = ["authToken" => $authToken,

"selectQuery" => "SELECT Email FROM Lead WHERE Id=1475450326663301794",];

$url = sprintf("%s?%s", "http://cirrus-shield.net/RestApi/Query", http_build_query($selectparam));$client = curl_init();

curl_setopt($client, CURLOPT_VERBOSE, true);curl_setopt($client, CURLOPT_RETURNTRANSFER, true);curl_setopt($client, CURLOPT_URL, $url);

$response = curl_exec($client)curl_close($client);

$array_data = json_decode($response, true);print_r('<pre>');var_dump($response);print_r('</pre>');return $response;

}

$username = "mail@mail.com";$password = "password";

$authToken = authenticate($username, $password);$authToken = str_replace(""", "", $authToken);

if ($authToken != '')

{

$selectLead = SelectLead($authToken);

} else {

echo "<br>Authentication Failed";

}?>

</body>

</html>

Was this article helpful to you? Yes No

How can we help?