How to migrate from REST to GraphQL APIs

Tags: Skills

Overview

Pluralsight’s APIs provide the most efficient way to unlock Pluralsight data and extend the platform into your internal systems and workflows. Pluralsight’s new APIs are powered by GraphQL, a technology that gives you exactly what you need, in an intuitive and efficient manner.

Pluralsight’s existing REST APIs offer a limited dataset focused on courses, usage, and user management. The new GraphQL APIs expand the datasets to channels, roles, skills, and more.

GraphQL gives the user the ability to replace multiple REST queries with a single query which includes explicit data requirements. 

How is GraphQL different from REST?

A single GraphQL query can fetch the complete array of data per the relationships defined in the schema, instead of multiple requests with REST. 

GraphQL allows for mutations, offering you the ability to perform create, update and delete operations, thereby replacing CRUD functionality in REST APIs. 

GraphQL has a greater number of API fields available. See the complete Pluralsight GraphQL Schema for fields and definitions but your queries are also simpler and more concise. 

Migrating from REST to GraphQL at Pluralsight

First, to use GraphQL APIs, you must be a Plan Admin on a Professional or Enterprise Plan, to create API keys and submit queries. 

Tip: if you’re a developer or analyst, you can still obtain data through APIs by having your Plan Admin generate and share their API key with you. 

If you’re unsure about whether you have Plan Admin permissions visit Manage Keys to check if you have permission to generate a new GraphQL API key. Only plan admins have the necessary permissions to generate a key. 

Once you have the necessary permissions, you are ready to use the developer portal, the primary developer resource for working with our APIs. 

If you want to start fresh with GraphQL, use the Developer Portal to:

  1. Generate an API key

  2. Learn how to build your First GraphQL API Query

  3. Copy one of the sample code snippets from the tables below to begin testing your Queries in the built-in Playground. Consult the schema to add or remove fields as required. 

If you prefer to modify your existing REST queries, here are some examples of how to modify your queries:

Course Daily Usage API

For applicable filters for the GraphQL Content Usage API, please see this resource.

Use this if you're looking to migrate from the REST Content Usage API.


REST API field

GraphQL API field

Sample code:

UserId

user { id }

{

    courseDailyUsage {

        nodes {

            user {

                id

                firstName

                lastName

                email

                team {

                    name

                }

                note

                isOnAccount

            }

            course {

                id

                slug

                title

            }

            rollupDate

            clipViewSeconds

        }

    }

}


FirstName

user { firstName }

LastName

user { lastName }

Email

user { email }

TeamName

user { team {name} }

Note

user { note }

IsOnAccount

user { isOnAccount }

ContentType

N/A

ContentId

course { id }

ContentSlug

course { slug }

ContentName

course { title }

ViewDate

rollupDate

UsageInSeconds

clipViewSeconds


Filters:

REST API Filter example

GraphQL API filter example

Example Description

&startDate=2019-12-04
&endDate=2019-12-04

filter: {
startDate: “2019-12-04”
endDate: “2019-12-04”
}

Use this filter to pull delta reports (example daily, weekly or biweekly reports) GraphQL API is based on the field lastActivityOn. Note: There could 24 hours data lag, so to get 24th data pull data on 26th

User API

Use this if you're looking to migrate from the REST Users API.

For applicable filters for the GraphQL Users  API, please see this resource.

REST API field

GraphQL API field

Sample code:

UserId

id

{

    users {

        nodes {

            id

            firstName

            lastName

            email

            startedOn

            note

            team {

                name

            }

        }

    }

}


Email

email

FirstName

firstName

LastName

lastName

StartDate

startedOn

Note

note

TeamName

team

N/A

isOnAccount

N/A

removedOn

N/A

ssoIdentifiers

N/A

ssoEnabled

N/A

planId

N/A

createdOn

N/A

additionalEmails

Note: By default, the Users API includes all current as well as historical licensed users on the plan. Use isCurrent userFilter to extract current users only.

Content Completion

If you are looking to migrate from the Content Completion REST API, there are two options available:

  1. CourseProgress API is currently in General Release and only provides data from Video Courses.  

  2. ContentProgress API use this to retrieve all content types like videos, guides, paths, interactive courses and projects. This API is currently in Beta.

Course Progress API

The GraphQL API courseProgress includes courses that are in progress.

REST API field

GraphQL API fields

Sample code:

UserId

user { id }

{

    courseProgress {

        nodes {

            user {

                id

                firstName

                lastName

                email

                team {

                    name

                }

                note

                isOnAccount

            }

            course {

                id

                title

                slug

            }

            firstViewedClipOn

            percentComplete

            isCourseCompleted

            completedOn

        }

    }

}


FirstName

user { firstName }

LastName

user { lastName }

Email

user { email }

TeamName

user { team {name} }

Note

user { note }

IsOnAccount

user { isOnAccount }

ContentType

N/A

ContentId

course { id }

ContentSlug

course { slug }

ContentName

course { title }

FirstActivityDate

firstViewedClipOn

PercentComplete

percentComplete

CompletionStatus

isCourseCompleted

CompletionDate

completedOn

For applicable filters for the Course Progress  API, please see this resource.

Content Progress API

For applicable filters for the Content Progress  API, please see this resource.

REST API field

GraphQL API fields

Sample code:

UserId

user { id }

{

contentProgress {

nodes {

user {

id

firstName

lastName

email

team {

name

}

note

isOnAccount

}

course {

id

title

slug

}

firstViewedClipOn

percentComplete

isCourseCompleted

completedOn

}

}

}

FirstName

user { firstName }

LastName

user { lastName }

Email

user { email }

TeamName

user { team {name} }

Note

user { note }

IsOnAccount

user { isOnAccount }

ContentType

ContentProgressType { ContentType }

ContentId

course { id }

ContentSlug

course { slug }

ContentName

course { title }

FirstActivityDate

firstViewedClipOn

PercentComplete

percentComplete

CompletionStatus

isCourseCompleted

CompletionDate

completedOn

Course Daily Usage API

Use this if you're looking to migrate from the REST course usage API.

For applicable filters for the GraphQL Course Daily Usage  API, please see this resource.


REST API field

GraphQL API field

Sample code:

UserId

user { id }

{

    courseDailyUsage {

        nodes {

            user {

                id

                firstName

                lastName

                email

                team {

                    name

                }

                note

                isOnAccount

            }

            course {

                id

                slug

                title

            }

            rollupDate

            clipViewSeconds

        }

    }

}



FirstName

user { firstName }

LastName

user { lastName }

Email

user { email }

TeamName

user { team {name} }

Note

user { note }

IsOnAccount

user { isOnAccount }

ContentType

N/A

ContentId

course { id }

ContentSlug

course { slug }

ContentName

course { title }

ViewDate

rollupDate

UsageInSeconds

clipViewSeconds

CompletionStatus

isCourseCompleted

CompletionDate

completedOn


Licence Management APIs

Member Invite API

Use this table if you’re looking to migrate from REST Get All Invites API.

Note: The REST API returns a note field by default. If you need the same field in GraphQL, call Users API and input the redeemedByUserId value in the filter as shown in the sample code.

REST API field

GraphQL API fields

Sample code:

None

inviteId

{
  memberInvites {
    nodes {
      inviteId
      planId
      sentToEmail
      teamId
      sentOn
      expiresOn
      redeemedByUserId
      status
    }
  }
}


{
  users(filter: {ids: “<Input redeemedByUserId value here>”}) {
    nodes {
      id
      note
    }
  }
}

 

-

planId

-

sentToEmail

-

teamId

-

user { note }

-

sentOn

-

expiresOn


Filters

REST API filters

GraphQL API filters

note

Not available; Pending enhancement

email

sentToEmail

teamId

Not available; Pending enhancement

The response fields available for this GraphQL API closely matches the response fields from REST API .


REST API field

GraphQL API fields

id

inviteId

email

sentToEmail

teamId

teamId

note

user { note }

sendDate

sentOn

expiresOn

expiresOn

Invite Member API -Mutation or Write API

Use this if you're looking to migrate from REST Invite new user API.

REST API field

GraphQL API fields

Sample code:

email

email

mutation {
  inviteMember(input: {
    email: “<insert email here>”,
    teamId: <Insert teamId here>,
    note: “<Insert note here>”}) {
    inviteId
    email
    teamId
    note
  }
}

teamId

teamId

note

note

Cancel Invite - Mutation or Write API 

Use this if you’re looking to migrate from REST Cancel invite API

REST API field

GraphQL API fields

Sample code:

id

inviteId

mutation {
  cancelInvite(input: {
     inviteId: “<Insert InviteID here>”}) {
       inviteId
   }
}

Users API

Use this if you’re looking to migrate from REST Get all Users API.

REST API field

GraphQL API fields

Sample code:

-

id

{

  users {

    nodes {

      id

      email

      additionalEmails

      firstName

      lastName

      startedOn

      createdOn

      note

      teams {

        edges {

          node {

            id

          }

        }

      }

      isOnAccount

      removedOn

      currentSsoIdentifier

    }

  }

}

-

additionalEmails

-

createdOn

-

teams { id }

-

firstName

-

lastName

-

email

-

note

-

startedOn

-

isOnAccount

-

removedOn

-

currentSsoIdentifier

Filters

REST API filters

GraphQL API filters

firstName

Not available

lastName

Not available

email

emails

note

notes

teamId

Not available; Pending enhancement

Not available

ssoIdentifiers

Not available

onlyCurrent


ids

The response fields available for this GraphQL API closely match the response fields from the REST API.

REST API field

GraphQL API fields

id

id

teamId

teams { id }

firstName

firstName

lastName

lastName

email

email

note

note

Get user by ID API

Use this if you’re looking to migrate from the REST Get user by ID API.

REST API field

GraphQL API fields

Sample code:

-

id

{

  users (filter: {ids:”<Insert user ID here>”})  {

    nodes {

      id

      email

      additionalEmails

      firstName

      lastName

      startedOn

      createdOn

      note

      teams {

        edges {

          node {

            id

          }

        }

      }

      isOnAccount

      removedOn

      currentSsoIdentifier

    }

  }

}


-

additionalEmails

-

createdOn

-

teams { id }

-

firstName

-

lastName

-

email

-

note

-

startedOn

-

isOnAccount

-

removedOn

-

currentSsoIdentifier


The response fields available for this GraphQL API closely match the response fields from REST API.

REST API field

GraphQL API fields

id

id

teamId

teams { id }

firstName

firstName

lastName

lastName

email

email

note

note

Edit user API - Mutation or Write API

Use this if you’re looking to migrate from REST update user API.

REST API field

GraphQL API fields

Sample code:

teamId

Use a separate API moveMemberToTeam

mutation {

  editUser (input: {

   userId: “<insert user ID>”, 

   firstName: “<Insert first name here>”,            

   lastName: “<insert last name>”, 

   email: “<“Insert email Id here>”, 

    remoteUserId: “<“Insert remote user ID here>”}) {

    userId

    firstName

    lastName

    email

    remoteUserId

  }

}


note

Not available

email

email

Not available

userId

Not available

firstName

Not available

lastName

Not available

remoteUserId


Remove user API - Mutation or Write API

Use this if you’re looking to migrate from REST Remove user API.

REST API field

GraphQL API fields

Sample code:

id

userId

mutation {

  removeUser(input:{userId:”<Insert user id here>“}){

    userId

  }

}

Teams API

Use this if you’re looking to migrate from REST Get all teams API.

REST API field

GraphQL API fields

Sample code:

id

id

{

 teams {

  nodes{

    id

    name

    planId

    groupId

    description

  }

}
}

name

name

Not available

planId

Not available

description

Not available

groupId

Filters

REST API filters

GraphQL API filters

name

name

Not available

description


back to top


If you need help, please email support@pluralsight.com for 24/7 assistance.