31,003
edits
m (→Nginx setup) Tag: 2017 source edit |
mNo edit summary Tag: 2017 source edit |
||
| Line 38: | Line 38: | ||
However, NGinx default setup on a lot of distribution is often a gaz engine and you may experience troubles. If you experience suche troubles, you can try to edit your NGinx config file to match the following example. This is a simple localhost setup with a working REST API handling (tested with 9.0.1 on parabola gnu/linux). | However, NGinx default setup on a lot of distribution is often a gaz engine and you may experience troubles. If you experience suche troubles, you can try to edit your NGinx config file to match the following example. This is a simple localhost setup with a working REST API handling (tested with 9.0.1 on parabola gnu/linux). | ||
< | <syntaxHighlight language="nginx"> | ||
worker_processes 1; | worker_processes 1; | ||
error_log /var/log/nginx/error.log; | error_log /var/log/nginx/error.log; | ||
| Line 93: | Line 93: | ||
} | } | ||
} | } | ||
</ | </syntaxHighlight> | ||
= List of provided services = | = List of provided services = | ||
| Line 130: | Line 130: | ||
< | <syntaxHighlight lang="php"> | ||
// Example of function to call a REST API | // Example of function to call a REST API | ||
function callAPI($method, $apikey, $url, $data = false) | function callAPI($method, $apikey, $url, $data = false) | ||
| Line 174: | Line 174: | ||
return $result; | return $result; | ||
}</ | }</syntaxHighlight> | ||
| Line 198: | Line 198: | ||
* $apiUrl = "<nowiki>http://<my_server>/api/index.php/</nowiki>"; | * $apiUrl = "<nowiki>http://<my_server>/api/index.php/</nowiki>"; | ||
< | <syntaxHighlight lang="php"> | ||
// Retrieve products list | // Retrieve products list | ||
$listProduits = []; | $listProduits = []; | ||
| Line 211: | Line 211: | ||
} | } | ||
} | } | ||
</ | </syntaxHighlight> | ||
Comments : | Comments : | ||
* I retrieve the 10'000 first products sorted on their ID in the base | * I retrieve the 10'000 first products sorted on their ID in the base | ||
| Line 218: | Line 218: | ||
< | <syntaxHighlight lang="php"> | ||
// Create a product | // Create a product | ||
$ref = "my_product_ref_X203ZZ"; | $ref = "my_product_ref_X203ZZ"; | ||
| Line 227: | Line 227: | ||
$newProductResult = CallAPI("POST", $apiKey, $apiUrl."products", json_encode($newProduct)); | $newProductResult = CallAPI("POST", $apiKey, $apiUrl."products", json_encode($newProduct)); | ||
$newProductResult = json_decode($newProductResult, true); | $newProductResult = json_decode($newProductResult, true); | ||
</ | </syntaxHighlight> | ||
Comments : | Comments : | ||
* before creating a product, it could be wise to check if it exists. Using my first example, you'll have : | * before creating a product, it could be wise to check if it exists. Using my first example, you'll have : | ||
< | <syntaxHighlight lang="php"> | ||
// my ref | // my ref | ||
$ref = "my_product_ref_X203ZZ"; | $ref = "my_product_ref_X203ZZ"; | ||
| Line 259: | Line 259: | ||
} | } | ||
} | } | ||
</ | </syntaxHighlight> | ||
Comments : | Comments : | ||
* I check if the ref of my product exist in the array created in the first example. | * I check if the ref of my product exist in the array created in the first example. | ||
| Line 268: | Line 268: | ||
Warning: The example below is not working properly. Creating an order and lines in one go is not supported. Instead you have to create an order first and with the returned order id add the lines using the /orders/{id}/lines endpoint. | Warning: The example below is not working properly. Creating an order and lines in one go is not supported. Instead you have to create an order first and with the returned order id add the lines using the /orders/{id}/lines endpoint. | ||
< | <syntaxHighlight lang="php"> | ||
// create an order with 2 products | // create an order with 2 products | ||
| Line 312: | Line 312: | ||
$newCommandeResult = json_decode($newCommandeResult, true); | $newCommandeResult = json_decode($newCommandeResult, true); | ||
} | } | ||
</ | </syntaxHighlight> | ||
Comments : | Comments : | ||
* $clientDoliId is the ID of the customer in the Dolibarr database. Either you know it or you can search for it before | * $clientDoliId is the ID of the customer in the Dolibarr database. Either you know it or you can search for it before | ||
| Line 318: | Line 318: | ||
< | <syntaxHighlight lang="php"> | ||
// Validate an order | // Validate an order | ||
$newCommandeValider = [ | $newCommandeValider = [ | ||
| Line 327: | Line 327: | ||
$newCommandeValiderResult = json_decode($newCommandeValiderResult, true); | $newCommandeValiderResult = json_decode($newCommandeValiderResult, true); | ||
</ | </syntaxHighlight> | ||
Comments : | Comments : | ||
* in this example, on the penultimate line, we can see : $apiUrl."orders/".$newCommandeResult."/validate".<br/> | * in this example, on the penultimate line, we can see : $apiUrl."orders/".$newCommandeResult."/validate".<br/> | ||
| Line 333: | Line 333: | ||
< | <syntaxHighlight lang="php"> | ||
// search in the database if a customer exist | // search in the database if a customer exist | ||
$customer_name = "Acme Inc"; | $customer_name = "Acme Inc"; | ||
| Line 345: | Line 345: | ||
) | ) | ||
), true); | ), true); | ||
</ | </syntaxHighlight> | ||
Comments : | Comments : | ||
* limit => 1 only 1 customer | * limit => 1 only 1 customer | ||
| Line 352: | Line 352: | ||
< | <syntaxHighlight lang="php"> | ||
// customer doesn't exist. Let's create it and get it's ID | // customer doesn't exist. Let's create it and get it's ID | ||
$newClient = [ | $newClient = [ | ||
| Line 363: | Line 363: | ||
$newClientResult = json_decode($newClientResult, true); | $newClientResult = json_decode($newClientResult, true); | ||
$clientDoliId = $newClientResult; | $clientDoliId = $newClientResult; | ||
</ | </syntaxHighlight> | ||
Comments : | Comments : | ||
* client => 1 He is a customer (not a supplier) | * client => 1 He is a customer (not a supplier) | ||