Scenario Session Data Sample Queries
The following queries are SAMPLES. As a consumer of the Scope GraphQL API, you can design and use any properly formed query to retrieve the data that you require.
For more information, see “Introduction to the Scope GraphQL API“.
Scenario Sessions with Quiz Data
Problem
As an analyst, I want to returns scenario sessions but also include any quiz related data.
Solution
Adding in filters into the scenario session events associated with the session will allow for only quiz data related events to be returned.
This kind of large queries are pretty expensive when getting a long list so it's recommended to use a small page size (i.e. `first: 25`) and make several paginated queries.
query {
scenarioSessions(first: 25) {
nodes {
id
databaseId
duration
endedAt
externalData
startedAt
endedAt
duration
sessionType
completedSteps {
nodes {
id
}
}
parts(first: 1, orderBy: { attribute: "startedAt", direction: DESC}) {
nodes {
databaseId
createdBy {
id
name
}
userInfo {
latitude
longitude
deviceOs
deviceModel
devicePlatform
}
}
}
scenario {
id
name
organization {
slug
}
}
scenarioRelease {
version
sdkVersion
workInstructionType
type
sequences {
nodes {
id
name
scenarioSteps(first: 1000) {
nodes {
id
name
orderIndex
type
scenarioSequence {
id
name
}
items(first: 1000) {
nodes {
id
description
type
}
}
}
}
}
}
}
steps(first: 1000, orderBy: {attribute: "startedAt", direction: ASC}) {
nodes {
id
completed
duration
completedItems {
nodes {
id
}
}
scenarioStep {
id
name
type
orderIndex
scenarioSequence {
id
name
}
items(first: 1000) {
nodes {
id
description
type
}
}
}
scenarioSessionEvents(
first: 1000
eventTypes: [QUIZ_ITEM_COMPLETE, CHECKLIST_ITEM_COMPLETE, SCREENSHOT_CAPTURED]
orderBy: {attribute: "startedAt", direction: DESC}
) {
nodes {
barcode
startedAt
type
value
photo {
fileUrl
}
scenarioStepItem {
id
}
}
}
}
}
}
}
}
Retrieve Scenario Sessions from Public (or Private) Scenarios
Problem
As an analyst, I only want to retrieve the sessions of a scenario that is publicly visible (or private).
Solution
Adding in the publicVisibility argument into the scenarios query allows for the scenarios to be filtered appropriately.
query {
scenarios(first: 100, scenariosQueryArguments: { publicVisibility: true }) {
nodes {
sessions(first: 10) {
nodes {
id
databaseId
startedAt
endedAt
organization {
id
databaseId
name
}
scenario {
id
databaseId
name
}
user {
id
databaseId
name
username
}
}
}
}
}
}
Session Data that excludes certain email domains
Problem
As an analyst, I want a list of scenario sessions that are not created by user with an email domain like public.scope.com
and are sorted by the scenario ID.
Solution
Unfortunately, our current API does not offer a way to filter by exclusion. However, it does provide a way to filter by inclusion, meaning that the query can be used to grab all sessions with a particular email domain. The query is grabbing the scenarios first, so the sessions will automatically be sorted by the scenario ID. However, scenarios and sessions must be paginated due to performance reasons:
query {
scenarios(first: 100, afterIndex: -1) {
nodes {
id
databaseId
name
sessions(first: 25, afterIndex: -1, fullText: "@scopear.com") {
nodes {
id
databaseId
startedAt
endedAt
organization {
id
databaseId
name
}
scenario {
id
databaseId
name
}
user {
id
databaseId
name
username
}
}
}
}
}
}
Scenario Session Step Data With Detailed Information
Problem
I want to retrieve scenario sessions but with lots of detailed information.
Solution
By adding to the data returned from the query, a lot of details can be shown for each scenario session. However, the results should be paginated for performance reasons.
Session Data Retrieval
Problem
As an analyst, I want to know which users have completed a particular Scenario so that I can issue credit to the users relating to the associated learning module in my system-of-record.
Solution
I will use a GraphQL client to retrieve Scenario Session data from the Scope GraphQL API which is not otherwise available in the Scope CMS user interface.
Procedure
The GraphiQL client application is installed and configured to communicate with the Scope GraphQL API (see “Exploring the Graph”)
The following query is executed:
The JSON response is reformatted to CSV (using any relevant tool) for merge with system-of-record data and/or reporting.
Retrieving A Single Scenario Session’s Data