Creating Group categories - D2L Valence

122 views Asked by At

I am attempting to dynamically create a group category with in a course using the following service:

[/d2l/api/lp/(version)/(orgUnitId)/groupcategories/ \[POST\]][1]

The following is the GroupData (Group.GroupData in Create form) JSON block that I am sending to this service:

{
    "Name": "New Group Category",
    "Description": {
       "Content": "",
       "Type": "HTML"
    },
    "EnrollmentStyle": 0,
    "EnrollmentQuantity": null,
    "AutoEnroll": false,
    "RandomizeEnrollments": false,
    "NumberOfGroups": 5,
    "MaxUsersPerGroup": null
} 

I am making the call with the user context of a administrative "Utility" account. I have 2 test courses, both of which I have confirmed I am able create the category through the web interface using this utility account.

My problem is I am having mixed results depending on the course that I try to create the category in. In one course the course returns 200-OK, in the other it returns 403-Forbidden.

Here are the (simplified) requests :

Call 1 /d2l/api/lp/1.4/350110/groupcategories/ Result: 403-Forbidden

Call 2 /d2l/api/lp/1.4/19988/groupcategories/ Result: 200-OK

The only difference is the OrgUnitID. Version, JSON, and user context are all the same, yet I'm getting 2 different results. I have tried with several other courses and again, I have success in some but not all; always receiving a 403 as the error.

After some investigation, I believe I have found 2 distinct differences between courses that are successful and those that return 403.

  1. Courses created just before April 2012 are successful, anything afterwards fail
  2. Courses with a 5 digit Org Unit ID are successful, anything with 6 digits seems to fail.

So my thoughts are we either applied a patch late march / early April of 2012 which somehow changed how courses are flagged on creation, OR somehow only 5 digits (or less?) Org IDs are being accepted by the service.

I'm hoping someone could provide some insight or verify they have no issue with 6+ digit OUIDs and group category creation.

1

There are 1 answers

0
Rich On

Further reviewing the documentation on API Responses - Disposition and error handling I realized that there are 3 possible cases for a 403 response:

  1. Response body contains Timestamp out of range
  2. Response body contains Invalid Token
  3. application or calling user context does not have the permissions required for the attempted action

Given this, I took a closer look at the response header and realized the issue was actually #2 "Invalid Token", not #3 as I was assuming.

Investigating my code further it seems the user defined SHA256 function I was using was producing an incorrect HASH/Signature when the data being hashed was exactly 55 characters long (yes I realize how crazy this sounds). The temporary work around is to pad my OrgIDs with leading zeros, so my request would actually look something similar too:

/d2l/api/lp/1.4/00350110/groupcategories/

Thankfully, this seems to work, and is acceptable for the immediate future. Long term solution will be to replace my SHA256 function with something more reliable.

I am using Colfusion 7MX for my development, which does not have a native SHA256 Hash function, hence the use of the user defined function.