Last active
December 11, 2015 20:39
-
-
Save aidvu/4657090 to your computer and use it in GitHub Desktop.
Get Emails related to a given Account, REST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$method = 'login'; | |
$parameters = array('user_auth' => array('user_name' => 'admin', 'password' => md5('admin'))); | |
$response = makeRESTCall($method, $parameters); | |
$session = $response['id']; | |
$method = 'get_relationships'; | |
$relationship = 'email_addresses'; | |
$module = 'Accounts'; | |
$id = '5f7ff434-eb56-b3b5-81cf-51069cf53a04'; | |
$relatedFields = array('id', 'email_address', 'invalid_email', 'opt_out'); | |
$parameters = array($session, $module, $id, $relationship, '', $relatedFields, array(), false); | |
$response = makeRESTCall($method, $parameters); | |
print_r($response); | |
function makeRESTCall($method, $parameters) | |
{ | |
// specify the REST web service to interact with | |
$url = 'http://127.0.0.1/Mango/ent/sugarcrm/service/v4/rest.php'; | |
// Open a curl session for making the call | |
$curl = curl_init($url); | |
// set URL and other appropriate options | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_POST, 1); | |
curl_setopt($curl, CURLOPT_HEADER, 0); | |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0); | |
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); | |
// build the request URL | |
$json = json_encode($parameters); | |
$postArgs = "method=$method&input_type=JSON&response_type=JSON&rest_data=$json"; | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs); | |
// Make the REST call, returning the result | |
$response = curl_exec($curl); | |
// Close the connection | |
curl_close($curl); | |
// Convert the result from JSON format to a PHP array | |
return json_decode($response,true); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment