API
This reference describes the Instruqt GraphQL API and helps you get started.
What is the GraphQL API?
The Instruqt GraphQL API lets you exchange data between your systems and the Instruqt platform. As the name suggests, the API is based on GraphQL, a query language for APIs. GraphQL lets you query and update data with queries and mutations in JSON format. This means that you can do the following actions with the Instruqt GraphQL API:
Query for information about Instruqt artifacts like tracks and challenges.
Add Instruqt artifacts like track invites or team members.
Update Instruqt artifacts, including deleting them.
The query response is in JSON format, and the following is an example of a GraphQL query that lists all your tracks by id
, slug
and title
:
Which gives a response like this:
Why would you use the GraphQL API?
The API is based on GraphQL, so you can form your own queries and are not bound to predefined requests and responses with unnecessary data. Furthermore, you can access the API from any modern programming language and software like Excel and Zapier.
Here are some possible scenarios:
You can extract a list with participant IDs from Instruqt.
You can add an Excel list with new team members to Instruqt.
You can add a JSON file with track invites to Instruqt.
How to use the GraphQL API
Address the API Endpoint
You address all your GraphQL queries and mutations as HTTP POST
requests to an API Endpoint. The GraphQL API Endpoint for Instruqt is:
Method | Endpoint |
---|---|
|
Create your API key for authorization
Instruqt GraphQL API requires your queries and mutations to be authorized by an API key. Take the following steps to create your API key:
Click Settings → API keys.
Click Generate API Key.
Click Copy to clipboard. ↳ You can apply the key now. You do that by passing the key to the HTTP request
Authorization: Bearer
parameter of your GraphQL query request.
Explore the API
Before you create queries and mutations, you should get familiar with the available queries and mutations and find the ones you need for your task—for example, list all tracks. You can explore the queries and mutations with the following resources:
The GraphQL Playground desktop app
Instruqt recommends GraphQL Playground, a GraphQL IDE that lets you explore an API and allows you to experiment with queries and mutations. You can download GraphQL and install it as a desktop app. Follow the installation instructions, start GraphQL Playground, and then:
Add the following HTTP header:
⇨ Replace
YOUR_API_KEY
with the copied key.In the Endpoint field, enter
https://play.instruqt.com/graphql
.Click the Docs tab. ↳ A list with QUERIES and MUTATIONS opens.
Browse through the queries and mutations to get familiar with them—for example, scroll to the
tracks
query and click the lemma for more information.Notice the TYPE DETAILS, listing track properties like
id
,slug
andtitle
.
Mandatory properties
Properties trailed with a ! are non-nullable and mandatory in queries and mutations.
You can also check the API reference. This reference contains the same information as the GraphQL Playground in a different format.
Create and run queries
List all your tracks and their play count
Now you are ready to create and run queries. First, let's create and run a query that lists all your tracks by id
, slug
, title
and play_count
:
Open a terminal and run the following curl example:
⇨ Replace
TEAM
with your team andYOUR_API_KEY
with the copied key.
You will get a response like this:
List challenges in a track and how many times they were started and completed
Next, let's list the challenges in the Kubernetes track with track ID vnt0zc9owl5c
and see how many times the challenges were started and finished:
Open a terminal and run the following curl example:
And the response will be something like this:
Create and run mutations
Add a track invite
First, head over to GraphQL Playground, search for the createTrackInvite
mutation, and inspect the details.
Next, create the mutation to add a track invite:
Open a terminal and run the following curl example:
⇨ Replace
TRACK-ID
with your track ID andYOUR_API_KEY
with the copied key. You can also enter your title.
The response will be something like this:
And if you move over to your team page in Web UI and click the Invites tab, you will see the newly created track invite.
Add a new team member
You can also add new team members with Instruqt GraphQL API. Again, first head over to GraphQL Playground and now search for the inviteOrganizationUser
mutation to inspect the details.
Next, add a new team member with the member
role:
Open a terminal and run the following curl example:
⇨ Replace
TEAM
with your team,EMAIL
with the new member's email, andYOUR_API_KEY
with the copied key.
The response will be something like this:
Delete a challenge
Inspect the details for the deleteChallenge
mutation in GraphQL Playground and then delete the Kubernetes dashboard challenge:
Open a terminal and run the following curl example:
The response will be like this:
Handling errors
Every GraphQL (HTTP Post) request responds with the status code 200
(OK), even if your query or mutation contains errors. So, you need to check the query or mutation response for signaling and handling errors. Let's see what an error response looks like by misspelling the organizationSlug
property in a query:
Open a terminal and run the following curl example:
⇨ Replace
TEAM
with your team andYOUR_API_KEY
with the copied key.
Now you will get an error response like this:
And you can process this error in your script or program.
Example: Updating track invites
Now let's look at a more extensive example in Python that updates all track invites with values set by you. The Python script queries all track invites and runs a mutation query for each track invite:
⇨ Replace YOUR\_API\_KEY
and YOUR\_TEAM
with your values.
⇨ Set the variables in lines 9 to 14 with your values.
↳ Lines 18 to 26 queries all track invites. ↳ Line 29 parses all track invites into a variable. ↳ Lines 30 to 57 run over all track invites and updates each track invite with the values you set.
Last updated