My goal is to be able to pass a variable (userid) to a php page that will list the total grade for each course for a particular student for a given term. Is this possible using REST? Thank you.
My goal is to be able to pass a variable (userid) to a php page that will list the total grade for each course for a particular student for a given term. Is this possible using REST? Thank you.
Yes - the REST APIs (Explore APIs ) support retrieving grades, so you should be able to do this.
But check the "Since:" in Explore APIs to check that the API calls you need are supported by your version of Learn.
Could you please provide an example? I have downloaded the php examples from here, but it does not include the grades. Thank you.
Sorry, I don't have a PHP example for grades.
Given the information at Explore APIs and the current php examples as a starting point, it should be straightforward to add gradebook calls.
My apologies for my ignorance. I don't have any experience working with REST apis. I have taken the current php examples and made some modifications to include grades. If someone could please look over this and let me know what I'm doing wrong, I would be grateful.
Rest.class.php
public function readGrades($access_token, $course_id, $user_id) { $constants = new Constants(); $grade = new Grade(); $request = new HTTP_Request2($constants->HOSTNAME . $constants->COURSE_PATH . '/' . $course_id . '/gradebook/users/' . $user_id, HTTP_Request2::METHOD_GET); $request->setHeader('Authorization', 'Bearer ' . $access_token); try { $response = $request->send(); if (200 == $response->getStatus()) { print "\n Read Grades...\n"; $grade = json_decode($response->getBody()); } else { print 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase(); $BbRestException = json_decode($response->getBody()); var_dump($BbRestException); } } catch (HTTP_Request2_Exception $e) { print 'Error: ' . $e->getMessage(); } return $grade; } }
Grade.class.php (created this one)
<?php class Grade { public $userId = ''; public $columnId = ''; public $status = ''; public $text = ''; public $score = ''; public $overridden = ''; public $notes = ''; public $feedback = ''; public $exempt = ''; public $corrupt = ''; }
grades.php (created this one)
<?php require_once('classes/Rest.class.php'); require_once('classes/Token.class.php'); require_once('classes/User.class.php'); require_once('classes/Course.class.php'); require_once('classes/Grade.class.php'); $rest = new Rest(); $token = new Token(); $course = new Course(); $user = new User(); $grade = new Grade(); $token = $rest->authorize(); var_dump($token); $access_token = $token->access_token; $user_id = $user->id; $user = $rest->readUser($access_token, $user_id); var_dump($user); $course_id = $course->id; $course = $rest->readCourse($access_token, $course_id); var_dump($course); $grade = $rest->readGrades($access_token, $course_id, $user_id); var_dump($grade); ?>
When I run the grades.php page, I get a list of all the users and courses on my test server. For the grades, I get an error.
Unexpected HTTP status: 404 Not Found
C:\wamp64\www\classes\Rest.class.php:619:
object(stdClass)[6]
public 'status' => int 404
public 'message' => string 'API is not found for the specified URL.' (length=39)
C:\wamp64\www\grades.php:30:
object(Grade)[2]
public 'userId' => string '' (length=0)
public 'columnId' => string '' (length=0)
public 'status' => string '' (length=0)
public 'text' => string '' (length=0)
public 'score' => string '' (length=0)
public 'overridden' => string '' (length=0)
public 'notes' => string '' (length=0)
public 'feedback' => string '' (length=0)
public 'exempt' => string '' (length=0)
public 'corrupt' => string '' (length=0)
What version of Learn are you using?
What values do you have for $course_id and $user_id?
My version of Blackboard is Release 3100.0.0-rel.51+0418b4f. I passing jdoe1234 as the userid and BBTEST01 as the courseid. At the top, I echoed out the course path just to see if my variables were coming through.
/learn/api/public/v1/courses/BBTEST01/gradebook/users/jdoe1234
Unexpected HTTP status: 404 Not Found
C:\wamp64\www\classes\Rest.class.php:619:
object(stdClass)[6]
public 'status' => int 404
public 'message' => string 'API is not found for the specified URL.' (length=39)
C:\wamp64\www\grades.php:32:
object(Grade)[2]
public 'userId' => string 'jdoe1234' (length=8)
public 'courseId' => string 'BBTEST01' (length=8)
public 'columnId' => string '' (length=0)
public 'status' => string '' (length=0)
public 'text' => string '' (length=0)
public 'score' => string '' (length=0)
public 'overridden' => string '' (length=0)
public 'notes' => string '' (length=0)
public 'feedback' => string '' (length=0)
public 'exempt' => string '' (length=0)
public 'corrupt' => string '' (length=0)
The courseid and userid need to be the primaries, unless you prefix them with things like externalId:, courseId:, userName:
Maybe you need to use courseId:BBTEST01 and userName:jdoe1234