Skip to main content
This function and all other functions in this graphql sdk are deprecated. Please migrate to the new rest api.

Required Permissions

  • courses:update

Usage

import { whopSdk } from "@/lib/whop-sdk";

const result = await whopSdk.courses.updateLesson({
	// Completion requirements for quiz/knowledge check lessons
	assessmentCompletionRequirement: {
		// The minimum grade percentage required to pass (0-100). Cannot be set together with minimum_questions_correct.
		minimumGradePercent: 10,

		// The minimum number of questions that must be answered correctly. Cannot be set together with minimum_grade_percent.
		minimumQuestionsCorrect: 10,
	},

	// Assessment questions for quiz/knowledge check lessons. Replaces all existing questions.
	assessmentQuestions: [
		{
			// The correct answer for the question. Used for short answer questions
			correctAnswer: "some string" /* Required! */,

			// The ID of an existing question. If provided, the question will be updated. If
			// not provided, a new question will be created.
			id: "xxxxxxxxxxx",

			// Optional image attachment for the question
			image: {
				// This ID should be used the first time you upload an attachment. It is the ID
				// of the direct upload that was created when uploading the file to S3 via the
				// mediaDirectUpload mutation.
				directUploadId: "xxxxxxxxxxx",

				// The ID of an existing attachment object. Use this when updating a resource and
				// keeping a subset of the attachments. Don't use this unless you know what you're doing.
				id: "xxxxxxxxxxx",
			},

			// The answer options for multiple choice/select questions
			options: [
				{
					// The ID of an existing option. If provided, the option will be updated. If not provided, a new option will be created.
					id: "xxxxxxxxxxx",

					// Whether this option is a correct answer
					isCorrect: true /* Required! */,

					// The text of the answer option
					optionText: "some string" /* Required! */,
				},
			],

			// The text of the question
			questionText: "some string" /* Required! */,

			// The type of the question
			questionType:
				"multiple_choice" /* Valid values: multiple_choice | multiple_select | short_answer | true_false */ /* Required! */,
		},
	],

	// General attachments for the lesson (PDFs, files, etc). Replaces all existing attachments.
	attachments: [
		{
			// This ID should be used the first time you upload an attachment. It is the ID
			// of the direct upload that was created when uploading the file to S3 via the
			// mediaDirectUpload mutation.
			directUploadId: "xxxxxxxxxxx",

			// The ID of an existing attachment object. Use this when updating a resource and
			// keeping a subset of the attachments. Don't use this unless you know what you're doing.
			id: "xxxxxxxxxxx",
		},
	],

	// The content of the lesson
	content: "some string",

	// Days from course start until unlock
	daysFromCourseStartUntilUnlock: 10,

	// ID for the embed (YouTube video ID or Loom share ID)
	embedId: "some string",

	// Type of embed for video lessons (youtube or loom)
	embedType: "loom" /* Valid values: loom | youtube */,

	// The ID of the lesson to update
	id: "xxxxxxxxxxx" /* Required! */,

	// The type of the lesson
	lessonType:
		"knowledge_check" /* Valid values: knowledge_check | multi | pdf | quiz | text | video */,

	// The main PDF file for this lesson
	mainPdf: {
		// This ID should be used the first time you upload an attachment. It is the ID
		// of the direct upload that was created when uploading the file to S3 via the
		// mediaDirectUpload mutation.
		directUploadId: "xxxxxxxxxxx",

		// The ID of an existing attachment object. Use this when updating a resource and
		// keeping a subset of the attachments. Don't use this unless you know what you're doing.
		id: "xxxxxxxxxxx",
	},

	// Maximum number of attempts allowed for assessments
	maxAttempts: 10,

	// The ID of the Mux asset to attach to this lesson for video lessons
	muxAssetId: "some string",

	// The thumbnail for the lesson in png, jpeg, or gif format
	thumbnail: {
		// This ID should be used the first time you upload an attachment. It is the ID
		// of the direct upload that was created when uploading the file to S3 via the
		// mediaDirectUpload mutation.
		directUploadId: "xxxxxxxxxxx",

		// The ID of an existing attachment object. Use this when updating a resource and
		// keeping a subset of the attachments. Don't use this unless you know what you're doing.
		id: "xxxxxxxxxxx",
	},

	// The title of the lesson
	title: "some string",

	// Determines how / whether this lesson is visible to users.
	visibility: "hidden" /* Valid values: hidden | visible */,
});

Example output

const result = {
	// The ID of the lesson
	id: "xxxxxxxxxxx",

	// The type of the lesson (text, video, pdf, multi, quiz, knowledge_check)
	lessonType:
		"knowledge_check" /* Valid values: knowledge_check | multi | pdf | quiz | text | video */,

	// The title of the lesson
	title: "some string",

	// The order of the lesson within its chapter
	order: 10,

	// The visibility of the lesson. Determines how / whether this lesson is visible to users.
	visibility: "hidden" /* Valid values: hidden | visible */,

	// The content of the lesson
	content: "some string",

	// Number of days from course start until the lesson is unlocked
	daysFromCourseStartUntilUnlock: 10,

	// The associated Mux asset for video lessons
	muxAsset: {
		// The ID of the Mux asset
		id: "xxxxxxxxxxx",

		// The Mux-provided ID of the asset
		muxAssetId: "some string",

		// The public playback ID of the Mux asset
		playbackId: "some string",

		// The signed playback ID of the Mux asset
		signedPlaybackId: "some string",

		// The signed thumbnail playback token of the Mux asset
		signedThumbnailPlaybackToken: "some string",

		// The signed video playback token of the Mux asset
		signedVideoPlaybackToken: "some string",

		// The signed storyboard playback token of the Mux asset
		signedStoryboardPlaybackToken: "some string",

		// The duration of the video in seconds
		durationSeconds: 10,

		// The status of the Mux asset
		status: "created" /* Valid values: created | ready | uploading */,

		// The time at which the video finished uploading
		finishedUploadingAt: 1716931200,
	},

	// Assessment questions for quiz/knowledge check lessons
	assessmentQuestions: [
		{
			// The ID of the assessment question
			id: "xxxxxxxxxxx",

			// The correct answer for the question. Used for short answer questions. Only
			// visible to admins (users with courses:update permission)
			correctAnswer: "some string",

			// Optional image attachment for the question
			image: {
				// The ID of the attachment
				id: "xxxxxxxxxxx",

				// A signed ID of the attachment to directly query the attachment
				signedId: "xxxxxxxxxxx",

				// Whether the attachment has been analyzed
				analyzed: true,

				// The size of the file in bytes
				byteSizeV2: "9999999",

				// The name of the file
				filename: "some string",

				// The attachment's content type (e.g., image/jpg, video/mp4)
				contentType: "some string",

				// The source of the attachment
				source: {
					// The URL to access the attachment
					url: "some string",
				},

				// The blurhash of the image
				blurhash: "some string",

				// The height of the video
				height: 10,

				// The width of the video
				width: 10,

				// The aspect ratio of the video
				aspectRatio: 10,

				// The preview of the video
				preview: {
					// The URL to access the attachment
					url: "some string",
				},

				// The duration of the audio in seconds
				duration: 10,

				// The URL of the waveform for the audio
				waveformUrl: "some string",
			},

			// The answer options for multiple choice/select questions
			options: [
				{
					// The ID of the assessment question option
					id: "xxxxxxxxxxx",

					// Whether this option is a correct answer. Only visible to admins (users with courses:update permission)
					isCorrect: true,

					// The text of the answer option
					optionText: "some string",

					// The order of this option within the question
					order: 10,
				},
			],

			// The order of the question within its lesson
			order: 10,

			// The text of the question
			questionText: "some string",

			// The type of the question
			questionType:
				"multiple_choice" /* Valid values: multiple_choice | multiple_select | short_answer | true_false */,
		},
	],

	// The attached files in this lesson
	attachments: {
		// A list of nodes.
		nodes: [
			{
				// The ID of the attachment
				id: "xxxxxxxxxxx",

				// A signed ID of the attachment to directly query the attachment
				signedId: "xxxxxxxxxxx",

				// Whether the attachment has been analyzed
				analyzed: true,

				// The size of the file in bytes
				byteSizeV2: "9999999",

				// The name of the file
				filename: "some string",

				// The attachment's content type (e.g., image/jpg, video/mp4)
				contentType: "some string",

				// The source of the attachment
				source: {
					// The URL to access the attachment
					url: "some string",
				},

				// The blurhash of the image
				blurhash: "some string",

				// The height of the video
				height: 10,

				// The width of the video
				width: 10,

				// The aspect ratio of the video
				aspectRatio: 10,

				// The preview of the video
				preview: {
					// The URL to access the attachment
					url: "some string",
				},

				// The duration of the audio in seconds
				duration: 10,

				// The URL of the waveform for the audio
				waveformUrl: "some string",
			},
		],
	},

	// The main PDF file for this lesson
	mainPdf: {
		// The ID of the attachment
		id: "xxxxxxxxxxx",

		// A signed ID of the attachment to directly query the attachment
		signedId: "xxxxxxxxxxx",

		// Whether the attachment has been analyzed
		analyzed: true,

		// The size of the file in bytes
		byteSizeV2: "9999999",

		// The name of the file
		filename: "some string",

		// The attachment's content type (e.g., image/jpg, video/mp4)
		contentType: "some string",

		// The source of the attachment
		source: {
			// The URL to access the attachment
			url: "some string",
		},

		// The blurhash of the image
		blurhash: "some string",

		// The height of the video
		height: 10,

		// The width of the video
		width: 10,

		// The aspect ratio of the video
		aspectRatio: 10,

		// The preview of the video
		preview: {
			// The URL to access the attachment
			url: "some string",
		},

		// The duration of the audio in seconds
		duration: 10,

		// The URL of the waveform for the audio
		waveformUrl: "some string",
	},
};