Last active
February 23, 2019 14:19
-
-
Save aphilippi/9604582 to your computer and use it in GitHub Desktop.
Factureaza.ro API: Basic examples
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 | |
//set BASE_URL to https://factureaza.ro/api/v1/ for production | |
define('BASE_URL', 'https://sandbox.factureaza.ro/api/v1/'); | |
//replace with the api key provided in the backend | |
define('API_KEY', '72543f4dc00474bc40a27916d172eb93339fae894ec7a6f2dceb4751d965'); | |
$attributes = array( | |
"client" => array( | |
"name" => 'Firma mea preferata', | |
"uid" => '3987985', | |
"tax_id" => 1, | |
"registration_id" => "J39/44/1990", | |
"city" => "Nume oras client", | |
"address" => "strada Buldozerului nr. 221", | |
"country_id" => "176" // Romania | |
) | |
); | |
$url = BASE_URL . 'clients.xml'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x"); | |
curl_setopt($ch, CURLOPT_URL, $url ); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($attributes)); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); // returns the newly created client in xml format | |
$header = curl_getinfo($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
if ($httpCode == 201) { | |
// transform the client data from xml to a array | |
$client_data = json_decode(json_encode(simplexml_load_string($result)), TRUE); | |
echo 'Client created successfully. Client id: ' . $client_data['id']; | |
} else { | |
echo '<pre> Error occured: ' . $httpCode . ':' . $result . '</pre>'; | |
} | |
?> |
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 | |
//set BASE_URL to https://factureaza.ro/api/v1/ for production | |
define('BASE_URL', 'https://sandbox.factureaza.ro/api/v1/'); | |
//replace with the api key provided in the backend | |
define('API_KEY', '72543f4dc00474bc40a27916d172eb93339fae894ec7a6f2dceb4751d965'); | |
$product_id = 741342700; // your product id here | |
$url = BASE_URL . 'products/' . $product_id . '.xml' ; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x"); | |
curl_setopt($ch, CURLOPT_URL, $url ); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); | |
$header = curl_getinfo($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
if ($httpCode == 200) { | |
echo 'Deleted successfully'; | |
} else { | |
echo '<pre> Error occured: ' . $httpCode . '</pre>'; | |
} | |
?> |
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 | |
//set BASE_URL to https://factureaza.ro/api/v1/ for production | |
define('BASE_URL', 'https://sandbox.factureaza.ro/api/v1/'); | |
//replace with the api key provided in the backend | |
define('API_KEY', '72543f4dc00474bc40a27916d172eb93339fae894ec7a6f2dceb4751d965'); | |
$client_id = 1064116434; // your client id here | |
$url = BASE_URL . 'clients/' . $client_id . '.xml' ; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x"); | |
curl_setopt($ch, CURLOPT_URL, $url ); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
echo '<pre>' . htmlentities($result) . '</pre>'; | |
?> |
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 | |
//set BASE_URL to https://factureaza.ro/api/v1/ for production | |
define('BASE_URL', 'https://sandbox.factureaza.ro/api/v1/'); | |
//replace with the api key provided in the backend | |
define('API_KEY', '72543f4dc00474bc40a27916d172eb93339fae894ec7a6f2dceb4751d965'); | |
$url = BASE_URL . 'clients.xml'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x"); | |
curl_setopt($ch, CURLOPT_URL, $url ); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
echo '<pre>' . htmlentities($result) . '</pre>'; | |
?> |
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 | |
//set BASE_URL to https://factureaza.ro/api/v1/ for production | |
define('BASE_URL', 'https://sandbox.factureaza.ro/api/v1/'); | |
//replace with the api key provided in the backend | |
define('API_KEY', '72543f4dc00474bc40a27916d172eb93339fae894ec7a6f2dceb4751d965'); | |
$url = BASE_URL . 'clients/search.xml?field=uid&value=13548146'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x"); | |
curl_setopt($ch, CURLOPT_URL, $url ); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
echo '<pre>' . htmlentities($result) . '</pre>'; | |
?> |
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 | |
//set BASE_URL to https://factureaza.ro/api/v1/ for production | |
define('BASE_URL', 'https://sandbox.factureaza.ro/api/v1/'); | |
//replace with the api key provided in the backend | |
define('API_KEY', '72543f4dc00474bc40a27916d172eb93339fae894ec7a6f2dceb4751d965'); | |
$client_id = 1064116434; // your client id here | |
$changes = array("client" => array("name" => 'Nume client nou', "city" => "Nume oras nou")); | |
$url = BASE_URL . 'clients/' . $client_id . '.xml' ; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERPWD, API_KEY . ":x"); | |
curl_setopt($ch, CURLOPT_URL, $url ); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($changes)); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); | |
$header = curl_getinfo($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
if ($httpCode == 200) { | |
echo 'Updated successfully'; | |
} else { | |
echo '<pre> Error occured: ' . $httpCode . ':' . $result . '</pre>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment