Course Context not Valid

Course Context not Valid

by Derek O Brien -
Number of replies: 0
Trying to use webservices to access courses externally with "get_course" but it fails every time and displays the following.

{"exception":"moodle_exception","errorcode":"errorcoursecontextnotvalid","message":"You cannot execute functions in the course context (course id:2). The context error message was: Course or activity not accessible."}


Can someone explain this error to me? 


To get more info i edited the externallib.php to dump the contex object which gave me the following 

context_course Object
(
    [_id:protected] => 481
    [_contextlevel:protected] => 50
    [_instanceid:protected] => 2
    [_path:protected] => /1/3/481
    [_depth:protected] => 3
)


 on inspection of the mdl_context table in the database the path resolves to : 


1 -> CONTEXT_SYSTEM -> 10

3 -> CONTEXT_COURSECAT -> 40 (Courses)

481 -> CONTEXT_COURSE -> 50 (Course "test")


Average of ratings: -