Uploading answers to formula question using API

barrybrown
Community Participant

I am trying to update an existing formula question to replace the list of possible answers with a new list. The idea here is to be able to generate a list of possible variable values and answers externally. For example, I may want the variables to have co-related dependencies, such as "x should be a random value between 1 and 10, and y should be between 0.75x and 1.5x".

I've tried this curl command, to simply upload a single answer to the question. I tried to match the syntax of the JSON array returned by the corresponding GET operation.

curl -s -H 'Authorization: Bearer MY_TOKEN' \
https://xyz.instructure.com/api/v1/courses/COURSEID/quizzes/QUIZID/questions/QUESTIONID \
-X PUT \
--data-urlencode 'question[answers]=[{"weight":100,"variables":[{"name":"d","value":10}],"answer":1000,"id":1234}]'

However, I get back a "internal server error" message.

To eliminate possible sources of error, I tried changing the name of the question using the question[question_name] attribute and that worked perfectly.

Please tell me this is possible, as it would greatly simplify my quizzes.

Labels (1)