OK, I actually hacked the shortanswer plugin and now I can get the userid, courseid and question name. I was hoping to also get the question category.
The question object does have a category field, but at the moment it is just an number, it doesn't have the actual question category.
Once I have userid, courseid, question category and question name, I can pass that to a url which will return a question specification or an answer as required.
The following is a section of the output when I use print_object with the question object (note that the category value is not the category):
$cat_id = $this->category;
$query = $DB->get_record_sql('select name from mdl_question_categories where id="' . $cat_id . '"');
Thanks for posting Charlie, that should work but you should consider something like
Then it will work if someone has a prefix other than mdl.
I suspect most people most of the time leave the default mdl_ but it is nice to cover unusual situations.
It's good to see an elegant approach.