Exemplu de script

Poți folosi următorul exemplu de scrip PHP pentru a evidenția produs de lucru al API prin Curl.

Exemplu de căutare (GET):

  • System ID (SystemId):  50
  • API Key (APIKey):  ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1
  • Requested project:  Test project
// Compile Url
$Url = 'https://50:ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1@r3.minicrm.hu/Api/R3/Project?Query=Teszt projekt';

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

// Pass the url to Curl
curl_setopt($Curl, CURLOPT_URL, $Url);

// Run Curl request
$Response = curl_exec($Curl);

// Was there a problem running the Curl request?
if(curl_errno($Curl)) $Error = "Eroare CURL : ".curl_error($Curl);

// Get the http code returned by the API
$ResponseCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
if($ResponseCode != 200) $Error = "Eroare API : {$ResponseCode} - mesaj: {$Response}";

// Close Curl
curl_close($Curl);

// Decode and print JSON received in response
$Response = json_decode($Response, true);
var_export($Response);

Exemplu de interogare a detaliilor (GET):

  • System ID (SystemId):  50
  • API Key (APIKey):  ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1
  • Project ID for  download : 12345
// Compile Url
$Url = 'https://50:ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1@r3.minicrm.hu/Api/R3/Project/12345';

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

// Pass the url to Curl
curl_setopt($Curl, CURLOPT_URL, $Url);

// Run Curl request
$Response = curl_exec($Curl);

// Was there a problem running the Curl request?
if(curl_errno($Curl)) $Error = "Eroare CURL: ".curl_error($Curl);

// Get the http code returned by the API
$ResponseCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
if($ResponseCode != 200) $Error = "Eroare API : {$ResponseCode} - mesaj: {$Response}";

// Close Curl
curl_close($Curl);

// Decode and print JSON received in response
$Response = json_decode($Response, true);
var_export($Response);

Exemplu creere card nou (PUT):

  • System ID (SystemId):  50
  • API Key (APIKey):  ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1
  • Data to upload:
    • Project Name: First API project
    • Responsible for the project: Bogdan Burciu (3200)
    • Project Status: Needs Assessment (2500)
    • Project produse  (obligatoriu pentru card nou): 3
// Compile Url
$Url = 'https://50:ZxPPCqDItuQhoaLeBM2679mT3iG5NgH1@r3.minicrm.hu/Api/R3/Project';

// Specify parameters in array format
$Params = array(
  'Name' => 'Proiect API',
  'UserId' => 3200,
  'StatusId' => 2500,
  'CategoryId' => 3
);

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

// Parameters JSON coding
$Params = json_encode($Params);

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

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

// Pass parameters to Curl
curl_setopt($Curl, CURLOPT_POSTFIELDS, $Params);

// Pass the url to Curl
curl_setopt($Curl, CURLOPT_URL, $Url);

// Run Curl request
$Response = curl_exec($Curl);

// Was there a problem running the Curl request?
if(curl_errno($Curl)) $Error = "Eroare CURL: ".curl_error($Curl);

// Get the http code returned by the API
$ResponseCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
if($ResponseCode != 200) $Error = "Eroare API: {$ResponseCode} - mesaj: {$Response}";

// Close Curl
curl_close($Curl);