Hi all,
I am currently trying to create a numerical question in a quiz using Python and the Canvas API. However, it seems that (no matter the numerical_answer_type) the answer values are always set to 0. Here is the code I am using:
import requests
import json
header = {'Authorization': f'Bearer {access_token}'}
course_id = 123
quiz_id = 456
base_url = f'https://canvas.instructure.com/api/v1'
new_question = {
'question_type': 'numerical_question',
'points_possible': 1,
'question_text': '<p>Give me a number.</p>',
'answers': [
{
'start': 10.0,
'end': 15.0,
'numerical_answer_type': 'range_answer'
},
{
'exact': 75.0,
'margin': 25.0,
'numerical_answer_type': 'exact_answer'
},
{
'approximate': 1000.0,
'precision': 5.0,
'numerical_answer_type': 'precision_answer'
}
]
}
canvas_json = {'question': new_question}
endpoint = f'{base_url}/courses/{course_id}/quizzes/{quiz_id}/questions'
resp = requests.post(endpoint, json=canvas_json, headers=header)
print(resp)
print(json.dumps(resp.json(), indent=2))
The response that I get back is exactly as expected, except that start, end, exact, margin, approximate, and precision are all 0, and is reflected as such on Canvas. I can manually update these values on Canvas, and GET-ing the question from there yields the correct values. What am I doing wrong and how do I properly create numerical questions through the API?
P.S. I've found a similar post from four years ago but no one seems to have answered it.