mkauffman

REST With cURL

Blog Post created by mkauffman on May 6, 2016

I may turn this into a document one day. For now, it's not so formal. For those who like to try things from a command line, here is how you can make the OAuth2 call for getting an access token, then use the token to start making REST calls to a Learn system.

Before running the example code you must register a developer account and application as described on the Developer Community What is the Developer Portal: Developer Registration and Application ManagementWhat is the Developer Portal: Developer Registration and Application Management and Managing REST Integrations in Learn: The REST Integrations Tool for System AdministratorsManaging REST Integrations in Learn: The REST Integrations Tool for System Administrators pages. You must also configure the script as outlined in the below Configure the Script section.

Get An Access Token

$ curl --user d128e50d-c91e-47d3-anoe-9d0keya77fb5d:jZljsn0tmys3crethIoRl370PYC36bGXixS52 --data "grant_type=client_credentials"  https://bd-partner-a-original.blackboard.com/learn/api/public/v1/oauth2/token

{"access_token":"XVSsvSe094K3m7H0XmJhHm1jre2DiBqs","token_type":"bearer","expires_in":713}

 

Where --user is the key:secret pair. (I've modified these, you'll need to get your own for your application.)

 

This is the equivalent of the following line in Mark O'Neil's REST Demo Using Python

auth.py:  r = session.post(OAUTH_URL, data=self.PAYLOAD, auth=(self.KEY, self.SECRET), verify=False)

 

Note: You can add the -k, --insecure option to the cURL to ignore the SSL certificate when working with the DVM. The Python code is doing this by setting verify=False.

 

Get Users

Then once we have the access token we can use it to make other REST requests. For example to get a list of the users from Learn:

$ curl -X GET -H "Authorization: Bearer XVSsvSe094K3m7H0XmJhHm1jre2DiBqs" https://bd-partner-a-original.blackboard.com/learn/api/public/v1/users

 

The above is the equivalent of the following line in the REST Demo Using Python:

user.py: r = session.get("https://" + self.target_url + self.users_Path, headers={'Authorization':authStr}, verify=False)

 

Get A Single User

$ curl -X GET -H "Authorization: Bearer XVSsvSe094K3m7H0XmJhHm1jre2DiBqs" https://bd-partner-a-original.blackboard.com/learn/api/public/v1/users/externalId:mkauffman

{"id":"_7_1","uuid":"1da16a2751ce4950b2d1ab4c3a1f7a15","externalId":"mkauffman","dataSourceId":"_2_1","userName":"mkauffman","studentId":"mark.kauffman@blackboard.com","educationLevel":"Unknown","gender":"Unknown","created":"2016-01-05T16:26:24.845Z","lastLogin":"2016-05-05T03:01:45.826Z","systemRoleIds":["SystemAdmin"],"availability":{"available":"Yes"},"name":{"given":"Mark","family":"Kauffman","title":"Mr"},"contact":{"email":"mark.kauffman@blackboard.com"}}

 

Update a User

$ curl --request PATCH -H "Authorization: Bearer XVSsvSe094K3m7H0XmJhHm1jre2DiBqs" -H "Content-Type: application/json" --data '{"externalId":"mkauffman","dataSourceId":"_2_1","userName":"mkauffman","availability":{"available":"Yes"},"name":{"given":"Joe","family":"Kauffman","title":"Mr"},"contact":{"email":"mark.kauffman@blackboard.com"}}' https://bd-partner-a-original.blackboard.com/learn/api/public/v1/users/externalId:mkauffman

{"id":"_7_1","uuid":"1da16a2751ce4950b2d1ab4c3a1f7a15","externalId":"mkauffman","dataSourceId":"_2_1","userName":"mkauffman","studentId":"mark.kauffman@blackboard.com","educationLevel":"Unknown","gender":"Unknown","created":"2016-01-05T16:26:24.845Z","lastLogin":"2016-05-08T03:59:14.535Z","systemRoleIds":["SystemAdmin"],"availability":{"available":"Yes"},"name":{"given":"Joe","family":"Kauffman","title":"Mr"},"contact":{"email":"mark.kauffman@blackboard.com"}}

 

References:

http://stackoverflow.com/questions/14140020/understanding-oauth2-client-credentials-flow

OAuth2 Quick Start Example · reddit/reddit Wiki · GitHub

Outcomes