Hi Matt,
According to the documentation page (here) I think I’m passing the right parameters in the right order but I may be wrong.
Here’s the code I’m using to test :
<?php
# the REST service
$url = "http://localhost/CRM/SuiteCRM-7.3.2/service/v4_1/rest.php/";
# login and password
$username = "admin";
$password = "password";
function call( $method, $parameters, $url ) {
ob_start();
$curl_request = curl_init();
curl_setopt( $curl_request, CURLOPT_URL, $url );
curl_setopt( $curl_request, CURLOPT_POST, 1 );
curl_setopt( $curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
curl_setopt( $curl_request, CURLOPT_HEADER, 1 );
curl_setopt( $curl_request, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $curl_request, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl_request, CURLOPT_FOLLOWLOCATION, 0 );
$jsonEncodedData = json_encode( $parameters );
$post = array(
"method" => $method,
"input_type" => "JSON",
"response_type" => "JSON",
"rest_data" => $jsonEncodedData
);
curl_setopt( $curl_request, CURLOPT_POSTFIELDS, $post );
$result = curl_exec( $curl_request );
curl_close( $curl_request );
$result = explode( "\r\n\r\n", $result, 2 );
$response = json_decode( $result[1] );
ob_end_flush();
return $response;
}
$login_parameters = array (
"user_auth" => array(
"user_name" => $username,
"password" => md5( $password ),
"version" => "1",
),
"application_name" => "RestTest",
"name_value_list" => array(),
);
$login_result = call( "login", $login_parameters, $url );
echo 'REST API -- Login : ';
echo "<pre>";
print_r($login_result); # login is working
echo "</pre>";
$session_id = $login_result->id;
$get_relationships_parameters = array(
'session' => $session_id,
'module_name' => 'Contacts',
'module_id' => '634a07c6-066a-f5d8-dff0-562e0020060c',
'link_field_name' => 'contacts_accounts',
'related_module_query' => " ",
'related_fields' => array(
'id',
'name'
),
'related_module_link_name_to_fields_array' => array(),
'deleted'=> 0,
'order_by' => '',
'offset' => 0,
'limit' => 200,
);
$result = call( "get_relationships", $get_relationships_parameters, $url );
echo 'REST API -- get_relationships : ';
echo "<pre>";
print_r($result); # Access Denied 40 You do not have access
echo "</pre>";
$get_entry_parameters = array(
'session' => $session_id,
'module_name' => "Contacts",
'id' => "634a07c6-066a-f5d8-dff0-562e0020060c",
'select_fields' => array(
'id',
'name',
),
'link_name_to_fields_array' => array(),
'track_view' => true,
);
$result = call ( "get_entry", $get_entry_parameters, $url );
echo "<pre>";
print_r($result); # get_entry works fine
echo "</pre>";
?>