User Tools

Site Tools


api_class

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
api_class [2020/11/22 15:21] sahlapi_class [2021/02/11 13:35] (current) – API query and handling files sahl
Line 90: Line 90:
 } }
 </code> </code>
-  + 
 + 
 +===== Handling file fields in the API ===== 
 +During normal operation the API will just return the ID of the file in file fields, but by passing the //include_binary_data// GET parameter with a value of 1, then these ID's will be replaced by a JSON structure: 
 + 
 +^filename|The filename of the file| 
 +^mimetype|The mime type of the file| 
 +^binary|The file binary data as base64| 
 + 
 +Please be aware that this can produce substantial output in some cases, and is therefore only recommended for using when querying for a specific object. 
 + 
 +A similar JSON structure can be used when posting to the API to update files. Just add another field to the JSON structure: 
 + 
 +^action|add to add a file and remove to remove the file currently in place.| 
 + 
 +If //remove// is passed the other fields are not necessary.  
 + 
 +===== Querying the API ===== 
 +The API endpoints can be queried by passing a JSON-structure in the //query// GET parameter. The query can consist of either a comparison statement or logical statement. 
 + 
 +==== Comparison statement ==== 
 + 
 +A comparison statement always consists of three fields: //type//, //fieldname// and //value//
 + 
 +The following comparison types exists: 
 + 
 +^Type^Meaning^ 
 +|Greater|Return everything where //fieldname// is greater than //value//.| 
 +|GreaterEqual|Return everything where //fieldname// is greater than or equal to //value//.| 
 +|Lesser|Return everything where //fieldname// is lesser than //value//.| 
 +|LesserEqual|Return everything where //fieldname// is lesser than or equal to //value//.| 
 +|Like|Return everything where //value// is contained in //fieldname//.| 
 +|Match|Return everything where //fieldname// equals //value//.| 
 +|OneOf|Return everything where //fieldname// is one of //value// and //value// is an array.| 
 + 
 +==== Logical statement ==== 
 + 
 +Logical statements are used to combine or negate other statements. They consists of the field: //type// and some additional fields depending on the type. 
 + 
 +^type^additional fields^Meaning^ 
 +|AND|//condition1//, //condition2//|Return everything which satisfies both //condition1// and //condition2// (where each is a statement)| 
 +|OR|//condition1//, //condition2//|Return everything which satisfies either //condition1// or //condition2// (where each is a statement)| 
 +|NOT|//condition//|Return everything which doesn't satisfies //condition// (where //condition// is a statement)| 
 + 
 +==== Examples ==== 
 +Find all data where age is equal or greater than 18 
 +<code javascript> 
 +{"type":"GreaterEqual","fieldname":"age","value":18} 
 +</code> 
 + 
 +Find all data where age is less than 40 and gender is male 
 +<code javascript> 
 +{"type":"AND","condition1":{"type":"Lesser","fieldname":"age","value":40},"condition2":{"type":"Match","fieldname":"gender","value":"male"}} 
 +</code> 
 + 
 +Find all data where firstname contains the letter a 
 +<code javascript> 
 +{"type":"Like","fieldname":"firstname","value":"a"
 +</code> 
 + 
 +Find all data changed since a specific time stamp 
 +<code javascript> 
 +{"type":"Greater","fieldname":"change_date","value":"2021-01-15 14:45:00"
 +</code>
api_class.1606058474.txt.gz · Last modified: 2020/11/22 15:21 by sahl

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki