Example programs

In this section, some example API programs will be shown, using Curl.

Example searching (GET):

  • SystemID: 50
  • API key: ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1
  • Project we want to find: Test Project
//Creating the URL
$Url = 'https://50:ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1@r3.minicrm.hu/Api/R3/Project?Query=Test Project';

//Initializing the Curl
$Curl = curl_init();
curl_setopt($Curl, CURLOPT_RETURNTRANSFER , true);
curl_setopt($Curl, CURLOPT_SSL_VERIFYPEER , false);

//Handover the URL to the Curl
curl_setopt($Curl, CURLOPT_URL, $Url);

//Execute the Curl request
$Response = curl_exec($Curl);

//Check for any errors in the Curl request
if(curl_errno($Curl)) $Error = "Hiba a Curl futtatásakor: ".curl_error($Curl);

//Request for the HTML response code
$ResponseCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
if($ResponseCode != 200) $Error = "API error code: {$ResponseCode} - Message: {$Response}";

//Closing the Curl
curl_close($Curl);

//Decoding and exporting the JSON response
$Response = json_decode($Response, true);
var_export($Response);

Example for downloading (GET):

  • SystemID: 50
  • API key: ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1
  • ID of the project we want to download: 12345
//Creating the URL
$Url = 'https://50:ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1@r3.minicrm.hu/Api/R3/Project/12345';

//Initializing the Curl
$Curl = curl_init();
curl_setopt($Curl, CURLOPT_RETURNTRANSFER , true);
curl_setopt($Curl, CURLOPT_SSL_VERIFYPEER , false);

//Handover the URL to the Curl
curl_setopt($Curl, CURLOPT_URL, $Url);

//Execute the Curl request
$Response = curl_exec($Curl);

//Check for any errors in the Curl request
if(curl_errno($Curl)) $Error = "Hiba a Curl futtatásakor: ".curl_error($Curl);

//Request for the HTML response code
$ResponseCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
if($ResponseCode != 200) $Error = "API Hibakód: {$ResponseCode} - Üzenet: {$Response}";

//Closing the Curl
curl_close($Curl);

//Decoding and exporting the JSON response
$Response = json_decode($Response, true);
var_export($Response);

 

Example for uploading (PUT):

  • SystemID: 50
  • API key: ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1
  • Project data we want to upload:
//Creating the URL
$Url = 'https://50:ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1@r3.minicrm.hu/Api/R3/Project';

//Creating the array for the parameters
$Params = array(
  'Name' => 'Első API projekt',
  'UserId' => 3200,
  'StatusId' => 2500,
  'CategoryId' => 3
);

//Initializing the Curl
$Curl = curl_init();
curl_setopt($Curl, CURLOPT_RETURNTRANSFER , true);
curl_setopt($Curl, CURLOPT_SSL_VERIFYPEER , false);

//Encoding the array to JSON
$Params = json_encode($Params);

//Setting up the headers (Content type, lenght and character encoding)
curl_setopt($Curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: '.strlen($Params), 'charset=UTF-8'));

//Setting the Curl request type to PUT
curl_setopt($Curl, CURLOPT_CUSTOMREQUEST, "PUT");

//Handover the array to the Curl
curl_setopt($Curl, CURLOPT_POSTFIELDS, $Params);

//Handover the URL to the Curl
curl_setopt($Curl, CURLOPT_URL, $Url);

//Executing the Curl request
$Response = curl_exec($Curl);

//Check if any error occurred during the request
if(curl_errno($Curl)) $Error = "Error: ".curl_error($Curl);

//Request for the HTML response code
$ResponseCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
if($ResponseCode != 200) $Error = "API error code: {$ResponseCode} - Message: {$Response}";

//Closing the Curl
curl_close($Curl);