REST - Create
The EWCreate (POST) operation...
- Creates a record in the specified KB and table with values for the specified fields.
- Accepts the URL with parameters as per general URL conventions and record data encoded as per Data Encoding, both of which can be viewed in the REST Interface.
- Supported Content-Type: application/x-www-form-urlencoded
- Returns the identifier of the newly created record.
- If this operation is used asynchronously, its status can be checked with EWAsyncStatus.
All parameters must be properly URL-encoded.
Example
Assume an instance of Agiloft is available on localhost, port 8080 and is called "Demo". Create a record for an employee named John Doe, that is assigned to the Service Manager group and Service Management Team, with login 'jdoe' and password 'password'.
Also, assume an instance of Agiloft is available on localhost.
- The Employee table is a sub-table of Contacts (logical table name = contacts.employees).
- To create the user we need to fill in the first_name, last_name, _login and password fields.
- We also need to create links with the groups and teams tables via linked fields that import multi-value fields groups and teams and a single-value field primary team.
- We will use the Query By Example capability and supply the names of the Service Manager group and Service Management Team.
The following request is issued:
http://localhost:8080/ewws/EWCreate?$KB=Demo&$table=contacts.employees&$login=admin&$password=qwerty&$lang=en&first_name=John&last_name=Doe&_login=jdoe&password=password&f_group=:Service Manager&teams=:Service Management Team&_106_sw_description=:Service Management Team&_1576_company_name0=:Agiloft
A result similar to the following will be returned in the case of successful record creation:
EWREST_id='353';
Here is an example of a JavaScript-based client that invokes the REST interface via AJAX:
function xmlhttpGet (strURL) { var xmlHttpReq=false; var self=this; // Mozilla/Safari if (window.XMLHttpRequest) { try { netscape.security.PrivilegeManager. enablePrivilege("UniversalBrowserRead"); } catch (e) { alert("Permission UniversalBrowserRead denied."); } self.xmlHttpReq=new XMLHttpRequest(); }// IE else if (window.ActiveXObject) { self.xmlHttpReq=new ActiveXObject("Microsoft.xmlHTTP"); } self.xmlHttpReq.open('GET', strURL, true); self.xmlHttpReq.onreadystatechange=requestComplete; self.xmlHttpReq.send(null); } function requestComplete() { if (xmlHttpReq.readyState==4||xmlHttpReq.readyState=="complete") { eval (self.xmlHttpReq.responseText); alert ("Id of new ticket"+EWREST_id); } } function main() { xmlhttpGet('http://localhost:8080/ewws/EWCreate?$KB=Demo&$table=contacts.employees&$login=admin&$password=qwerty&$lang=en&first_name=John&last_name=Doe&_login=jdoe&password=password&f_group=:Service Manager&teams=:Service ManagementTeam&_106_sw_description=:Service ManagementTeam&_1576_company_name0=:Agiloft'); }
Related articles