資源
Games over the Content API

Games over the Content API

The game object, its brief, and the metadata keys that shape its plan. Create, list, and update classroom games from an external system.

本頁內容

A game is a playable web page built from a practice objective. Games use the same operations and credit prices as the TutorFlow editor. Every route is under /v1/content/classrooms/{classroomId}/games and takes a tf_content_ key.

Planning, building, revising, restoring, and sharing work the same way for games and simulations, and are described once in Generation: Brief, Build, Revise. This page covers what is specific to games. The full route list is in the API Reference.

The game object

Create, read, update, and restore return the same shape. content appears only on GET /games/{gameId}.

FieldNotes
idUse as {gameId} on later calls.
classroomIdThe classroom the game belongs to.
title, descriptionDisplay text. description may be null. While title still equals metadata.topic, a generated brief replaces it with the game's own name.
visibilityPRIVATE or PUBLIC. A public, built game opens at its play page (publicUrl) without an account.
slugA short label TutorFlow assigns. It is not part of any link.
metadataAn object you own. The keys in Metadata that shapes the plan feed the brief; other keys are stored untouched, except that sending language also stores isLanguageChosen: true.
briefThe plan the build reads. null until a brief is generated or written. See The brief.
contentKeyStorage reference of the version being served. An opaque identifier, not a URL. null until the first build.
contentVersionThe version being served. 0 until the first build, then incremented by every build, revision, and restore.
buildHistoryOne entry per version: version, contentKey (opaque), createdAt, source (build, revision, or restore), note with the revision feedback when there was one, and restoredFromVersion on a restore. A save from the visual editor in TutorFlow also adds a revision entry, with note: "Visual editor" and no feedback; it cost no credits.
thumbnailStorage reference of a capture of the opening screen, or null. An opaque identifier, not a URL.
contentThe built game as one complete HTML document, or null before the first build. Only on GET /games/{gameId}.
createdAt, updatedAtTimestamps. Sort the list by updatedAt to find recent changes.
editorUrlThe game in the TutorFlow editor, for a person signed in to TutorFlow as an admin of the organization. null in the sandbox classroom.
publicUrlThe play page, https://tutorflow.io/games/play/{gameId}, while the game is PUBLIC and built. null otherwise and in the sandbox classroom.

content is the whole page and can be large, so lists never include it. To show a game to people, set it to PUBLIC and send publicUrl, or serve the HTML from content yourself. See Check and share what you made.

The brief

A generated brief has these fields. Write your own with PATCH /games/{gameId} and a brief object to skip the priced brief call.

FieldNotes
titleShort, concrete title for the game.
pitchOne sentence on what playing it is like.
coreLoopThe action the player repeats.
mechanicsTwo to five rules or devices the game is built from.
levelsTwo to six entries of name, goal, and twist.
winCondition, failConditionWhat ends a run either way.
controlsHow it is played, by keyboard and by touch.

Metadata that shapes the plan

The TutorFlow create wizard stores its answers on metadata, and the brief reads the same keys. All are optional. PATCH merges metadata: keys you send replace their old values, and keys you leave out stay.

KeyValuesNotes
topicFree textWhat the game teaches. Falls back to title.
audienceFree textWho plays it.
objectiveFocusFree textThe skill a round should exercise.
mechanicFree textA mechanic to build around, if you have one in mind.
dimension2d or 3dDefaults to 2d. It does not change the price.
persistencesession or localWhether progress survives a reload. Defaults to session.
playLengthshort, standard, or deepDefaults to standard.
visualStyleFree textArt direction for the page.
languageLanguage name or codeLanguage of on-screen text. When unset, the plan infers it from topic, objectiveFocus, and referenceMarkdown; set it to be sure.
referenceMarkdownMarkdownYour own material to ground the plan. POST /brief can override it per call.

Create a game

title and visibility are required. Create it PRIVATE, and set it PUBLIC once the build has been checked (you read content, or a person opens editorUrl).

bash
curl -X POST "$TUTORFLOW_API_BASE_URL/v1/content/classrooms/$CLASSROOM_ID/games" \
  -H "Authorization: Bearer $TUTORFLOW_CONTENT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: game:fractions-run:v1" \
  -d '{
    "title": "Fractions run",
    "description": "Practice comparing fractions under time pressure.",
    "visibility": "PRIVATE",
    "metadata": {
      "topic": "Comparing fractions with unlike denominators",
      "audience": "Grade 5",
      "objectiveFocus": "Decide which of two fractions is larger",
      "playLength": "short",
      "language": "en",
      "externalId": "game:fractions-run"
    }
  }'

The response is 201 with the game object, contentVersion: 0, brief: null.

List games

HTTP
GET /v1/content/classrooms/{classroomId}/games?page=1&limit=20&field=updatedAt&order=DESC&search=fraction
Authorization: Bearer tf_content_...
ParameterDefaultNotes
page11-based.
limit20Values above 100 are clamped to 100. take is a deprecated alias.
fieldcreatedAttitle, createdAt, or updatedAt. Anything else returns 422 with error.allowedValues.
orderDESCASC or DESC. Ties break on id.
searchCase-insensitive substring of title.
updatedSinceISO 8601 date-time. Only games updated at or after it.

The response is the list envelope with game objects without content. The same parameters work on every resource list; see List pages.

Update a game

PATCH /games/{gameId} is partial. It accepts title, description, visibility, brief, thumbnail, and metadata, and returns 200 with the updated game. description cannot be set to null (422); send an empty string. A new thumbnail must be a storage key under the classroom, for example from an upload. contentKey and contentVersion belong to the build pipeline and cannot be set.

Other routes

The rest of the game routes are listed in the API Reference: DELETE /games/{gameId}, POST .../brief, POST .../build, POST .../revise, GET .../run, and POST .../versions/{version}/restore (takes Idempotency-Key). The brief, build, and revise steps are described in Generation. Single reads and PATCH carry an ETag; send If-Match on PATCH to avoid overwriting a change made elsewhere. See Concurrency.

這個頁面對你有幫助嗎?