Loading All Results

Apart from loading a single test attempt's report, you may want to load the results of all tests you have conducted. This results table will contain data such as the start and end time of a test, the Trust Score and so on. It will look something like this.

The .showResults() method

Unlike a single test attempt's report, we are looking to fetch all test attempts' details. So we can't use a single testAttemptId in the credentials object like earlier. Instead, here the credentials object should contain the current UNIX time in seconds (10 digits).

In JS, you can get this with the Date.now() function. This is the unixTimestamp variable in credentials. If unixTimestamp is more than 60 seconds older than when the AutoProctor server receives the request, you will receive a 403 Forbidden response to this request.

You will then hash the UNIX time, like you hashed the Test Attempt ID earlier. This will be sent as hashedUnixTimestamp in credentials. This is unusual, but:

  • The hashing ensures that the results are available only if you have the Secret Key
  • The time constraint on unixTimestamp ensures that if the hashed value becomes available to an unauthorized user at some point, they can't continue to load the report forever.
const unixTimestamp = Date.now()
const hashedUnixTimestamp = getHashedValue(unixTimestamp, CLIENT_SECRET)
const credentials = {
  clientId: CLIENT_ID,
  unixTimestamp: unixTimestamp,
  hashedUnixTimestamp: hashedUnixTimestamp
}
const apInst = new AutoProctor(credentials)
const resultsOptions = {...}
apInst.showResults(resultsOptions)

The reportUrlPrefix

As you can see in the sample results dashboard, for each test attempt row, there is a field that links to the report for that test attempt. The exact route on which this report loads depends on how your website is configured. For example, if the results table is loaded on yourwebsite.com/ap/results, maybe you want to load the report of Test Attempt ID abc123 on yourwebsite.com/ap/results/abc123. The reportUrlPrefix option lets you specify what should be prefixed to the testAttemptId so that a hyperlink can be constructed for the specific Test Attempt's report.

For this example, reportUrlPrefix = /ap/results so that if testAttemptId is xyz456, for that row, the hyperlink to the report will be /ap/results/xyz456. If you do not want the report URL on the results page, set the option to null. The URLs have "target='_blank'" attribute set.

Grouping tests with the lookupKey

If you have used a lookupKey while setting up the test attempt, you can restrict the results to only those with that lookupKey.

The resultsOptions object

These are the different keys of the reportOptions object.

keydatatypemeaningdefault
reportUrlPrefixstrThe string that gets prefixed to the testAttemptId to load the report for that Attempt/ap/reports
resultsDOMIdstrThe DOM element to load the results table ontoap-results
lookupKeystrThe lookup key by which to filter resultsnull
includeUnfinishedboolShould tests that have not been marked as finished be shown in the tablefalse
columnsToHidearrayArray of keys for the columns that you want to hide. Possible keys are "index", "name", "email", "startedAt", "finishedAt", "trustScore", "reportUrl"null

Getting the results as a JSON

Instead of rendering the SDK's table, you may want to render the data using your own UI. For this, you can call the .getResults() method

const results = apInst.getResults(resultsOptions)

This method takes the same options as the showResults() method, except for reportUrlPrefix and resultsDOMId. It returns the results as a JSON, as shown below. You may then show the results using your own UI.

[
  {
    "trustScore": 0.79,
    "testAttemptId": "1639076",
    "startedAt": "2023-01-26T09:22:43.050316+00:00",
    "finishedAt": "2023-01-26T09:23:09.273894+00:00",
    "miscData": {
      "userDetails": null
    },
    "userAgentString": null,
  },
  {
    "trustScore": 0.23,
    "testAttemptId": "2576806",
    "startedAt": "2021-12-12T12:38:43.302000+00:00",
    "finishedAt": "2021-12-12T12:39:59.448418+00:00",
    "miscData": {
      "userDetails": {
        "name": "Tom Sawyer", "email": "tomsawyer@example.com"
      }
    },
    "userAgentString": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 desktop Safari/537.36",
    "lookupKey": "abc"
  },
  {
    "testAttemptId": "6137469",
    "startedAt": "2021-12-12T12:41:10.301000+00:00",
    "userAgentString": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
    "trustScore": null,
    "finishedAt": null
  }
]