How to register for a PROMIS assessment through the API
Syntax
- https://promis.consultlia.com//2014-01/Assessments/{OID}{.xml or .json}
This will return a token that will be used for accessing the assessment requested.
Remarks
- OID is the 'primary key' to the form.
- The request header for the API takes optional parameters ('UID' and 'Expiration').
- You can either GET or POST requests to this API.
- UID = a user-defined id for this assessment instance.
- Expiration = time limit for when the assessment should be completed by (in days).
Sample code for https://promis.consultlia.com//2014-01/Assessments
<script langauge="javascript" src="jquery-1.7.1.min.js"></script> <script language="javascript" src="crypto.js"></script> <script type='text/javascript' version='1.3'> var Server = https://promis.consultlia.com/; var FormOID = "FFCDF6E3-8B17-4673-AB38-C677FFF6DBAF"; // Sample form -- replace with your FormOID function startAssessment(FormOID) { $.ajax({ url: Server + "/2014-01/Assessments/" + FormOID + ".json", cache: false, type: "POST", data: "UID=" + document.getElementById("UID").value, dataType: "json", beforeSend: function(xhr) { var bytes = Crypto.charenc.Binary.stringToBytes(document.getElementById("txtRegistration").value + ":" + document.getElementById("txtToken").value); var base64 = Crypto.util.bytesToBase64(bytes); xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data) { var container = document.getElementById("Content"); for (var k= container.childNodes.length - 1 ; k > -1; k--) { container.removeChild(container.childNodes[k]) } container.appendChild(document.createTextNode("AssessmentID:" + data.OID)); container.appendChild(document.createElement("br")); container.appendChild(document.createTextNode("User-defined ID:" + data.UID)); container.appendChild(document.createElement("br")); container.appendChild(document.createTextNode("Expiration:" + data.Expiration)); }, error: function(jqXHR, textStatus, errorThrown) { document.write(jqXHR.responseText + ':' + textStatus + ':' + errorThrown); } }) }
Based on twillio example to call RESTful services. (http://www.twilio.com/docs/api/rest)
using System; using System.Collections; using System.Configuration; using System.IO; using System.Net; using System.Web; using System.Text; using System.Text.RegularExpressions; public class TestHarness { static void Main(string[] args) { string REGISTRATIONID ="31839849-ECE0-4F5E-BEAE-3D655ED65E31"; // Sample registration -- replace with your RegistrationOID string TOKEN ="F3738486-5A7D-41EF-8044-DCBAF800E2D4"; // Sample token -- replace with your TokenOID string FormOID = "FFCDF6E3-8B17-4673-AB38-C677FFF6DBAF"; // Sample form -- replace with your FormOID string API_URL = "https://promis.consultlia.com//2014-01/Assessments/" + FormOID + ".json"; string UID = "UID=" + HttpUtility.UrlEncode(args[0]) + "&"; // Optional user-defined id string Expiration = "Expiration=" + HttpUtility.UrlEncode(args[1]) + "&"; // Optional expiration (default = 3 days) string data = UID + Expiration; string authstring = Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("{0}:{1}", REGISTRATIONID, TOKEN))); ServicePointManager.Expect100Continue = false; Byte[] postbytes = Encoding.ASCII.GetBytes(data); WebClient client = new WebClient(); client.Headers.Add("Authorization", String.Format("Basic {0}", authstring)); client.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); byte[] resp = client.UploadData(API_URL, "post", postbytes); Console.WriteLine(Encoding.ASCII.GetString(resp)); } }
// Requesting to administer FormOID "C0E737C9-EF7C-4842-8661-4B00F82C0FED"
// NOTE: "OID" is the AssessmentOID, not the FormOID
Request:https://promis.consultlia.com//2014-01/Assessments/C0E737C9-EF7C-4842-8661-4B00F82C0FED.json
Response:
// NOTE: "OID" is the AssessmentOID, not the FormOID
Request:https://promis.consultlia.com//2014-01/Assessments/C0E737C9-EF7C-4842-8661-4B00F82C0FED.json
Response:
{ "OID": "901A493B-7A6E-4711-B483-82AB100FE430", "UID": "", "Expiration": "10/21/2015 12:13:57 PM" }
// Requesting to administer FormOID "C0E737C9-EF7C-4842-8661-4B00F82C0FED"
Request:https://promis.consultlia.com//2014-01/Assessments/C0E737C9-EF7C-4842-8661-4B00F82C0FED.json
Response:
Request:https://promis.consultlia.com//2014-01/Assessments/C0E737C9-EF7C-4842-8661-4B00F82C0FED.json
Response:
<?xml version="1.0" encoding="utf-16"?> <Assessment OID="901A493B-7A6E-4711-B483-82AB100FE430" UID="" Expiration="10/21/2015 12:13:57 PM" />