Paginating Query Results in Alexa Education Skills

The Alexa.Education request that Alexa sends your skill always contains a maxResults field in the payload. Your skill can return fewer results than maxResults, but not more. If there are more results, you must paginate them.

Paginating Results

If you have more results than the maxResults value, the payload of your response must contain a paginationContext object that contains a nextToken field. Alexa then sends a new Get request to your skill. The new request is similar to the previous request, but has the nextToken field set to the value from your earlier response. Your response must return results starting from this token and provide the nextToken value only if there are further results.

The following example shows the requests and responses for a GetCourses request when maxResults is three and totalResults is eight. That is, Alexa requests data with a maximum of three results at a time, and there are eight results total.

1. Initial Alexa Get request

"payload": {
  "queryParameters": {
    "maxResults": "3"
  }
}

2. Initial skill response with nextToken

"payload": {
  "nextToken": "4",
  ... result 1 ...
  ... result 2 ...
  ... result 3 ...
}

3. Alexa Get request with nextToken

"payload": {
  "queryParameters": {
    "maxResults": "3",
    "nextToken": "4"
  }
}

4. Skill response

"payload": {
  "nextToken": "7",
  ... result 4 ...
  ... result 5 ...
  ... result 6 ...
}

5. Alexa Get request

"payload": {
  "queryParameters": {
    "maxResults": "3",
    "nextToken": "7"
  }
}

6. Final skill response without nextToken

"payload": {
  ... result 7 ...
  ... result 8 ...
}