View ProjeQtOr On SourceForge.net
ProjeQtOr - Project Management Tool
Support us on Capterra
OIN - Open Invention Network
ProjeQtOr free project management software - How to add a new oject with the API - ProjeQtOr
 

How to add a new oject with the API

More
27 Feb 2025 14:29 - 06 Mar 2025 09:24 #1 by CAIE_guens
Hi all,
I tested many things but all never do what I want.
I want to Client with the API, client come from another DB but I' made a script test
$apiUrl = 'http://serveur/projeqtor/api/Client'; // Données du nouveau client
$data = array('name' => 'ZORRO','description' => 'Description du client','email' => 'This email address is being protected from spambots. You need JavaScript enabled to view it.'); // Convertir les données en JSON
$jsonData = json_encode($data); // Clé de cryptage (doit être de 32 octets pour AES-256)
$encryptionKey = '4c91fbdc52cb573f6625adb2a407dbe3'; // Générer un IV (Initialisation Vector) aléatoire
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); // Chiffrer les données
$encryptedData = openssl_encrypt($jsonData, 'aes-256-cbc', $encryptionKey, 0, $iv); // Encoder les données chiffrées et l'IV en base64 pour les transmettre
$encryptedData = base64_encode($encryptedData);$iv = base64_encode($iv); // Préparer les données à envoyer
$postData = json_encode(array('data' => $encryptedData,'iv' => $iv)); // Identifiants API
$apiUser = 'projapi';$apiPassword = 'i5yMUwLdeYD356';
 // Initialiser cURL
$ch = curl_init($apiUrl); 
// Configurer les options cURLcurl_
setopt
($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);curl_setopt($ch, CURLOPT_USERPWD, "$apiUser:$apiPassword"); // Exécuter la requête et obtenir la réponse$response = curl_exec($ch); // Vérifier les erreurs cURLif ($response === false) {die('Erreur cURL : ' . curl_error($ch));} // Fermer cURLcurl_close($ch); // Afficher la réponseecho 'Réponse de l\'API : ' . $response; 

where is the problem ?
Thanks
Guénolé
Last edit: 06 Mar 2025 09:24 by CAIE_guens.

Please Log in or Create an account to join the conversation.

More
07 Mar 2025 09:29 #2 by CAIE_guens
Hi,
Iwant to add a ticket for example with the API.
This is the return :
root@vm-dolibarr:/home/http/API_ProjeqtorV1# php projATicket.php
Données avant chiffrement : {"id":"1", "name":"name to be changed for Ticket 1"}

Données après chiffrement : HAPtP0atymdmP0NsWMm00LuBzh/4/eVf/JNqbZPAjE1alzxmYa3KHYY07hggQpaOH+ciAv7Gtk0nd8Spt3acZ+x3qQEgIg==

Réponse décryptée : "{\"id\":\"1\", \"name\":\"name to be changed for Ticket 1\"}"
Json Payload : {"data":"HAPtP0atymdmP0NsWMm00LuBzh\/4\/eVf\/JNqbZPAjE1alzxmYa3KHYY07hggQpaOH+ciAv7Gtk0nd8Spt3acZ+x3qQEgIg=="}
*   Trying 192.168.12.10:80...
* TCP_NODELAY set
* Connected to 192.168.12.10 (192.168.12.10) port 80 (#0)
* Server auth using Basic with user 'projapi'
> POST /projeqtor/api/Ticket HTTP/1.1
Host: 192.168.12.10
Authorization: Basic cHJvamFwaTppNXlNVXdMZGVZRDM1Ng==
Accept: */*
Content-Type: application/json
Content-Length: 110

* upload completely sent off: 110 out of 110 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Fri, 07 Mar 2025 08:24:38 GMT
< Server: Apache/2.4.41 (Ubuntu)
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
< Set-Cookie: PHPSESSID=p3e8v1e9tpdn365tjj0bq5uusu; path=/
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=UTF-8
<
* Connection #0 to host 192.168.12.10 left intact
Réponse de l'API : {"status":"success","message":"Donn\u00e9es re\u00e7ues","data":"{\"id\":\"1\", \"name\":\"name to be changed for Ticket 1\"}"}{"error":"invalid API query", "message":""'data' is not correctly encoded for method POST. Request for correct API KEY""}

Could someone help please ?
Thanks
Guenole

Please Log in or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.074 seconds

Cookies settings

×

Functional Cookies

Ce site utilise des cookies pour assurer son bon fonctionnement et ne peuvent pas être désactivés de nos systèmes. Nous ne les utilisons pas à des fins publicitaires. Si ces cookies sont bloqués, certaines parties du site ne pourront pas fonctionner.

Session

Please login to see yours activities!

Other cookies

Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.