Forum

API evolution - a s...
 
Notifications
Retirer tout

API evolution - a search web service

10 Posts
2 Utilisateurs
0 Reactions
11.8 {numéro}K Vu
 BEAU
(@mamath)
Posts: 24
Active Member
Début du sujet
 
[#1940]

Hi,

First, thank you for your excellent work on the API. It's a very interesting functionnality.
Two point :
- Question : is it necessary too encrypt message (with AES-256) if i call the web service using https ? I try too call the web service using microsoft WinHttpRequest. and i have lot of problem with encryption.
- Propose Evolution : add a service for search elements with criteria. Sample : if i want know if a project named "Project ONE" exist, i can ask this web service with a criteria : '{"name":"Project ONE"}'. This evolution can help, if we want check existence of object before using insert or update WS.

I can give you the code i have developed.

Regards


 
Posté : 10 Août PM 14:088
(@babynus)
Posts: 14952
Membre Admin
 

Question : is it necessary too encrypt message (with AES-256) if i call the web service using https ? I try too call the web service using microsoft WinHttpRequest. and i have lot of problem with encryption.

Yes, encryption is mandatory. It is a security constraint, not to crypt data, but to confirm you have the correct API Key. Security (to retrive access rights) is in two points :
- you have to connect with correct user/password (means you have an account)
- you provide the correct API key (in fact you don't really provide it, you use it to code data) : this means the admin gave you this API key, and is OK for you to post data through the API.

Propose Evolution : add a service for search elements with criteria. Sample : if i want know if a project named "Project ONE" exist, i can ask this web service with a criteria : '{"name":"Project ONE"}'. This evolution can help, if we want check existence of object before using insert or update WS.

Request recorded as Ticket #1490


 
Posté : 10 Août PM 15:088
 BEAU
(@mamath)
Posts: 24
Active Member
Début du sujet
 

Hi,

Thank you for your answer.
For the Ticket #1490, if you want i have develop the functionality in a simple way (I have add a case like "filter", but named "search").
If you want you can use the following code:

else if (count($split)==2 and $split[1]=='search') {  // =============== uri = {OblectClass}/search
		    	if (isset($_REQUEST['data']) ) {
		    		$data=$_REQUEST['data'];
		    	} else {
		    		$data=file_get_contents("php://input");
		    	}
		    	if (! $data) {
		    		returnError($invalidQuery, "'data' missing for method ".$_SERVER['REQUEST_METHOD']);
		    	}
		    	$dataArray=@json_decode($data,true);
		    	if (! $dataArray) {
		    		returnError($invalidQuery, "'data' is not correctly encoded for method ".$_SERVER['REQUEST_METHOD'].". Request for correct API KEY");
		    	}
		    	if (isset($dataArray['items'])) {
		    		$arrayData=$dataArray['items'];
		    	} else {
		    		$arrayData=array($dataArray);
		    	}
		    	$where="1=1 ";
		    	
		    	foreach ($arrayData[0] as $field=>$value) {
		    		$where.="and " . $field . "='" .$value . "' ";
		    	}
        } 

best regards


 
Posté : 12 Août PM 21:088
(@babynus)
Posts: 14952
Membre Admin
 

Note added to Ticket #1490

Thanks


 
Posté : 13 Août PM 18:088
 BEAU
(@mamath)
Posts: 24
Active Member
Début du sujet
 

Hi,

I have modify my proposed code to add to the search service the capability to use "OR" conditions.
for exemple if you want to get activity close OR canceled, you can send a query like : {"identifier":"id","items":[{"idStatus":"7"},{"idStatus":"9"}]}

else if (count($split)==2 and $split[1]=='search') {  // =============== uri = {OblectClass}/search
		    	if (isset($_REQUEST['data']) ) {
		    		$data=$_REQUEST['data'];
		    	} else {
		    		$data=file_get_contents("php://input");
		    	}
		    	if (! $data) {
		    		returnError($invalidQuery, "'data' missing for method ".$_SERVER['REQUEST_METHOD']);
		    	}
		    	$dataArray=@json_decode($data,true);
		    	if (! $dataArray) {
		    		returnError($invalidQuery, "'data' is not correctly encoded for method ".$_SERVER['REQUEST_METHOD'].". Request for correct API KEY");
		    	}
		    	if (isset($dataArray['items'])) {
		    		$arrayData=$dataArray['items'];
		    	} else {
		    		$arrayData=array($dataArray);
		    	}
		    	$where=(count($arrayData))>0?"(1=0 ":"(1=1";
		    	foreach ($arrayData as $arrayFilter) {
		    		$where.="or (1=1 ";
			    	foreach ($arrayFilter as $field=>$value) {
			    		$where.="and " . $field . "='" .$value . "' ";
			    	}
			    	$where.=') ';
		    	}
		    	$where.=') ';
		    }

 
Posté : 8 Sep PM 12:099
(@babynus)
Posts: 14952
Membre Admin
 

Hi,

Thanks for this new code.
Added as note on Ticket #1490.

But I'm not sure a "OR" condition should be used.
In most cases, several criterias means "AND" conditions (as in Filters pop-up).

Have to be studied.
Anyhow, Thanks for your contribution


 
Posté : 8 Sep PM 15:099
 BEAU
(@mamath)
Posts: 24
Active Member
Début du sujet
 

Hi,

I personnaly use OR expression because i have to make report of imputation of a project; but this project has sub projects. to get all imputation i have to call get method of "Work" class for each sub-project. If i don't use OR condition i need to call the get method for the project but also for each sub-project. In this cas you understand that it's more easy to call "Work" object with all project id as criteria?

I'm not sure to be clear ?

In any case thank, for your work.

Bye


 
Posté : 9 Sep AM 02:099
(@babynus)
Posts: 14952
Membre Admin
 

I personnaly use ...

But what about generic use of API ?


 
Posté : 9 Sep PM 14:099
 BEAU
(@mamath)
Posts: 24
Active Member
Début du sujet
 

Hi,
I'm not sure too understood your question. You ask me for a feedback of the use of the API ?


 
Posté : 9 Sep PM 15:099
(@babynus)
Posts: 14952
Membre Admin
 

No, it is just a remark.
The way you implemented the filters (with OR criteria) fits your own need.
But is it a generic use, for all users, of filters for API ? I don't think so...


 
Posté : 9 Sep PM 16:099
Share:
Retour en haut