instructure/canvas-lms · error · GraphQL::ExecutionError

You must provide targetGroupId or targetContextId and…

Error message

You must provide targetGroupId or targetContextId and targetContextType

What it means

ImportOutcomes requires a destination: either targetGroupId, or the pair targetContextId + targetContextType. When neither (both blank) is supplied, get_target raises this before any import runs, because there is nowhere to import outcomes into.

Solutions

  1. Pass targetGroupId of an active LearningOutcomeGroup, or both targetContextId ('1') and targetContextType ('Account' or 'Course')
  2. If targeting a context, remember the import goes into its root_outcome_group
  3. Validate input on the client before sending; both targetContext fields are required together
  4. Update integrations to prefer targetGroupId (comment in code: it should become required)

Example fix

// before
importOutcomes(input: { outcomeId: "42" })
// after
importOutcomes(input: { outcomeId: "42", targetGroupId: "5" });
// or
importOutcomes(input: { outcomeId: "42", targetContextId: "1", targetContextType: "Account" });
Defensive patterns

Strategy: validation

Validate before calling

function validateImportTarget(input) {
  if (!input.targetGroupId && !(input.targetContextId && input.targetContextType)) {
    throw new Error("You must provide targetGroupId or targetContextId and targetContextType");
  }
}

Try / catch

try {
  await importOutcomes(input);
} catch (e) {
  if (e.message.includes("You must provide targetGroupId")) {
    // default to the current context's rootOutcomeGroup as target and retry
  }
}

Prevention

When it happens

Trigger: Calling importOutcomes with groupId/outcomeId but omitting all target arguments; sending null/empty strings for targetGroupId, targetContextId, and targetContextType; a client bug dropping the target input fields.

Common situations: Older clients built before target_group_id was introduced; template requests with target fields left blank; serializers omitting empty optional fields; confusion about the two mutually compatible targeting styles.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/b879eb59b83c3972. Report an issue: GitHub.

Appendix: source

Thrown at app/graphql/mutations/import_outcomes.rb:320

      group
    end
  end

  private

  def get_target(input)
    if input[:target_group_id]
      target_group = LearningOutcomeGroup.active.find_by(id: input[:target_group_id])
      if target_group.nil?
        raise GraphQL::ExecutionError, I18n.t("no such target group")
      end

      target_context = target_group.context

      [target_context, target_group]
    else
      if input[:target_context_type].blank? && input[:target_context_id].blank?
        raise GraphQL::ExecutionError, I18n.t(
          "You must provide targetGroupId or targetContextId and targetContextType"
        )
      elsif input[:target_context_type].blank? && input[:target_context_id].present?
        raise GraphQL::ExecutionError, I18n.t(
          "targetContextType required if targetContextId provided"
        )
      elsif input[:target_context_type].present? && input[:target_context_id].blank?
        raise GraphQL::ExecutionError, I18n.t(
          "targetContextId required if targetContextType provided"
        )
      end

      target_context =
        begin
          context_class(input[:target_context_type]).find_by(
            id: input[:target_context_id]
          )
        rescue NameError

View on GitHub (pinned to 1c9f0bb801)