通过API创建问题

时间:2018-07-23 14:46:01

标签: api canvas-lms

我正在尝试通过API在Canvas LMS中向测验添加问题。

文档在这里:https://canvas.instructure.com/doc/api/quiz_questions.html#method.quizzes/quiz_questions.create

但是它似乎不起作用:

curl -s 'https://canvas.url/api/v1/courses/1571/quizzes/517/questions' -X POST -d @data.json   -H "Authorization: Bearer $CANVAS_TOKEN" | jq -r '.'

data.json:

{
  "question": {
    "question_name": "Question",
    "question_text": "<p>test</p>",
    "question_type": "essay_question",
    "points_possible": 1
  }
}

但是,画布似乎完全忽略了所有参数,并创建了一个默认的空问题:

{
  "id": 1446,
  "quiz_id": 517,
  "quiz_group_id": null,
  "assessment_question_id": null,
  "position": null,
  "question_name": "Question",
  "question_type": "text_only_question",
  "question_text": "Question text",
  "points_possible": 0,
  "correct_comments": "",
  "incorrect_comments": "",
  "neutral_comments": "",
  "correct_comments_html": "",
  "incorrect_comments_html": "",
  "neutral_comments_html": "",
  "answers": [],
  "variables": null,
  "formulas": null,
  "answer_tolerance": null,
  "formula_decimal_places": null,
  "matches": null,
  "matching_answer_incorrect_matches": null,
  "assessment_question": null
}

有人成功通过API创建问题吗?

修改

“已解决”:

curl -s 'https://canvas.url/api/v1/courses/1571/quizzes/517/questions' \
  -X POST \
  -F 'question[question_name]=Question' \
  -F 'question[question_text]= <p>test</p>' \
  -F 'question[question_type]=essay_question' \
  -F 'question[points_possible]=1' \
  -H "Authorization: Bearer $CANVAS_TOKEN" | jq -r '.'

按预期工作。请注意<p>test之前的空格。如果空间不存在,它将无法正常工作。

我尝试将空间添加到json:

{
  "question": {
    "question_name": "Question",
    "question_text": " <p>test</p>",
    "question_type": "essay_question",
    "points_possible": 1
  }
}

-这不起作用。

编辑2

结果是我缺少内容类型:

curl -s 'https://canvas.url/api/v1/courses/1571/quizzes/519/questions' \
  -X POST \
  -d @data.json \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $CANVAS_TOKEN" | jq -r '.'

现在它可以正常工作了。

0 个答案:

没有答案