Appframe Knowledge Base


3 hits
3

Using Rest API to return result a API resource

Example of how to retrieve documents in Pims Document Control function getDocuments(){ jQuery.ajax({ url: "https://api.pimsdevhosting.com/dcs/documents/?take=100", type: "GET", beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "Basic " + btoa("Username" + ":" + "Password")); xhr.setRequestHeader("Accept","application/json"); }, success: function(resultData) { //here is your json. console.log(resultData); }, error : function(jqXHR, textStatus, errorThrown) { }, timeout: 120000, }); }

rest api web · Perma link post comment Posted by: Johnny Vik (10-jun-2015)

D. Young Hoang :
for sorting results, add parm ?order=["Title","OtherField"] or ?order=[{"desc":"Title"},{"asc","OtherField"}] This is important for paging since skip 0 or no skip does not implement row_number() causing the final results to skew... issue https://www.pims.no/issues/issue?43709 (03-jul-2018)
3

Using Rest API to execute a procedure in Pims

Example of how to use the RestAPI to execute a procedure in Pims: function execProcOnAPI(){ var vData = { "Timeout": 30, "AwaitResult": true, "@DocumentType": "AA", "@Title": "Sample Doc", "@DocGroup": "Administrative", "@FacilityID":"A", "@OriginatorCompany":"AOGD", "@Discipline": "A", "@NewDocumentID":"", "@AddSheetNo":false, "@ContractNo":null, "@WorkPackID":null, "@SubProjectID":null, "@System":null, "@Area":null, "@PONumber":null }; jQuery.ajax({ url: "https://api.pimsdevhosting.com/procedure/dcsCreateNewDocumentID/call", data: JSON.stringify(vData), contentType: "application/json", dataType: "json", type: "POST", beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "Basic " + btoa("UserName" + ":" + "Password")); }, success: function(resultData) { //here is your json. console.log(resultData); }, error : function(jqXHR, textStatus, errorThrown) { console.log(errorThrown); }, timeout: 120000 }); }

rest api web · Perma link post comment Posted by: Johnny Vik (10-jun-2015)

0

REST API resource call from Swift

The SendRequestToRest function below takes the following paramets: RequestURL - Example: https://api.pimsdevhosting.com/dcs/document-search?take=-1 Username Password The function will return a NSDictionary, containing either the result from the resource call, or an error message. func SendRequestToREST(RequestURL : String, Username : String, Password : String, DataLoadedHandler: (RESTResult: NSDictionary) -> Void){ //REST API requires user credentials to be base64 encoded let UserLoginBase64 = Base64EncodeUserString(Username, Password: Password) let url = NSURL(string: RequestURL) //Create request, and add REST API request headers. let request = NSMutableURLRequest(URL: url!) request.HTTPMethod = "GET" request.addValue("Basic " + UserLoginBase64, forHTTPHeaderField: "Authorization") request.addValue("application/json", forHTTPHeaderField: "Accept") //Send asynchronous request with our URL and request headers. let session = NSURLSession.sharedSession() let task = session.dataTaskWithRequest(request, completionHandler: { data, response, error -> Void in if error == nil{ //Parse json response let resultDictionary: NSDictionary = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary DataLoadedHandler(RESTResult: resultDictionary) }else{ let ErrorMessage: NSDictionary = ["Connection Error":"Could not connect to service, please verify that your connection string is correct."] DataLoadedHandler(RESTResult: ErrorMessage) } }) task.resume() } //Function that is utilized to encode the user credentials in the request header. private func Base64EncodeUserString(Username : String, Password: String) -> String { let UserLoginString = Username + ":" + Password let UserLoginPlainData = (UserLoginString as NSString).dataUsingEncoding(NSUTF8StringEncoding) return UserLoginPlainData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) }

rest api · Perma link post comment Posted by: Steffen Opheim (17-aug-2015)