End Point 1: https://absc-staging.blackboard.com/learn/api/public/v1/oauth2/token
End Point 2: https://absc-staging.blackboard.com/learn/api/public/v3/courses
Function get_BB_token() Returns array of string
Local boolean &ret;
Local string &authStr, &clientId, &clientSecret, &responseStr;
Local array of string &result = CreateArrayRept("", 20);
/* Application Key */
&clientId = "9c18bcc1-8be4-4f61-a2e8-815baaac9e2e1";
/*Secret*/
&clientSecret = "KlT4VdO0sclGwtQuGvcLkPlALo7fF3Kk1";
&request = CreateMessage(Operation.X_RCVD_BB_TOKEN_POST);
&ret = &request.IBInfo.LoadRESTHeaders();
&request.URIResourceIndex = 1;
&request.SegmentContentType = "application/x-www-form-urlencoded;charset=UTF-8";
Local object &plainStr = CreateJavaObject("java.lang.String", &clientId | ":" | &clientSecret);
Local object &encoder = GetJavaClass("com.peoplesoft.tools.util.Base64");
&authStr = &encoder.encode(&plainStr.getBytes());
Local string &postData = "grant_type=client_credentials";
&ret = &request.IBInfo.IBConnectorInfo.AddConnectorProperties("Authorization", "Basic " | &authStr, %HttpHeader);
&ret = &request.SetContentString(&postData);
&response = %IntBroker.SyncRequest(&request);
If &response.ResponseStatus = %IB_Status_Success Then
Local string &jsonRespStr = &response.GetContentString();
Local JsonParser &parser = CreateJsonParser();
&ret = &parser.Parse(&jsonRespStr);
Local JsonObject &jsonResp = &parser.GetRootObject();
&result [1] = &jsonResp.GetProperty("access_token");
&result [2] = &jsonResp.GetProperty("token_type");
&result [3] = &jsonResp.GetProperty("expires_in");
&result [4] = &jsonResp.GetProperty("scope");
rem MessageBox(0, "", 0, 0, "Response: " | &result [1]);
Return &result;
Else
rem MessageBox(0, "", 0, 0, "Error: " | &response.ErrorText);
Return &response.ErrorText;
End-If;
End-Function;
/*----------------------------------------------------------------------*/
Local array of string &result1 = get_BB_token();
/* Use the result */
&access_token = &result1 [1];
&token_type = &result1 [2];
If &access_token = "" Then
/* Handle error case */
Error MessageBox(0, "", 0, 0, "Error: Token is not valid");
Else
Local boolean &ret1, &organization, &allowGuests, &allowObservers, &closedComplete, &force;
Local object &rootJSON, &availabilityJSON, &durationJSON, &enrollmentJSON, &localeJSON;
&Request_MSG = CreateMessage(Operation.X_RCVD_BB_TOKEN_POST);
&ret1 = &request.IBInfo.LoadRESTHeaders();
&ret1 = &Request_MSG.IBInfo.IBConnectorInfo.AddConnectorProperties("Method", "POST", %Property);
&ret1 = &Request_MSG.IBInfo.IBConnectorInfo.AddConnectorProperties("Authorization", "Bearer " | &access_token, %HttpHeader);
&ret1 = &Request_MSG.IBInfo.IBConnectorInfo.AddConnectorProperties("Content-Type", "application/json", %HttpHeader);
rem Error MessageBox(0, "", 0, 0, "1" | &_accessToken);
&rootJSON = CreateJsonObject();
Local string &url = "learn/api/public/v3/courses";
&Request_MSG.IBInfo.ConnectorOverride = True;
&Request_MSG.OverrideURIResource(" ");
If Len(&url) > 0 Then
&Request_MSG.OverrideURIResource(&url);
End-If;
Local SQL &sqlHeader = CreateSQL(SQL.X_GET_COURSE_DTL, "2401");
While &sqlHeader.Fetch(&CRSE_ID, &CRSE_OFFER_NBR, &STRM, &SESSION_CODE, &CLASS_SECTION, &CLASS_NBR, &SUBJECT, &CATALOG_NBR, &DESCR);
&externalId = &CRSE_ID | "-" | NumberToString("%02", &CRSE_OFFER_NBR) | "-" | &STRM | "-" | &SESSION_CODE | "-" | &CLASS_SECTION | "-" | NumberToString("%05", &CLASS_NBR);
&courseId = &SUBJECT | &CATALOG_NBR | "-" | NumberToString("%02", &CRSE_OFFER_NBR) | "-" | &STRM | "-" | &SESSION_CODE | "-" | &CLASS_SECTION | "-" | NumberToString("%05", &CLASS_NBR);
&name = &DESCR | " " | &CLASS_SECTION | "-" | NumberToString("%05", &CLASS_NBR);
&description = &SUBJECT | " " | &CATALOG_NBR;
&organization = False;
&ultraStatus = "Ultra";
&allowGuests = False;
&allowObservers = False;
&closedComplete = False;
&termId = "_241_1";
&available = "Yes";
&type = "Continuous";
&type1 = "InstructorLed";
&force = True;
/*-------------------------------------------------*/
&durationJSON = CreateJsonObject();
&durationJSON.AddProperty("type", "Continuous");
&durationJSON.AddProperty("start", "2024-06-24T12:46:26.588Z");
&durationJSON.AddProperty("end", "2024-06-24T12:46:26.588Z");
&durationJSON.AddProperty("daysOfUse", 0);
&availabilityJSON = CreateJsonObject();
&availabilityJSON.AddProperty("available", "Yes");
&availabilityJSON.AddProperty("duration", &durationJSON);
&enrollmentJSON = CreateJsonObject();
&enrollmentJSON.AddProperty("type", "InstructorLed");
&enrollmentJSON.AddProperty("start", "2024-06-24T12:46:26.588Z");
&enrollmentJSON.AddProperty("end", "2024-06-24T12:46:26.588Z");
&enrollmentJSON.AddProperty("accessCode", "01");
&localeJSON = CreateJsonObject();
&localeJSON.AddProperty("id", "string");
&localeJSON.AddProperty("force", True);
&rootJSON.AddProperty("externalId", &externalId);
&rootJSON.AddProperty("courseId", &courseId);
&rootJSON.AddProperty("name", &name);
&rootJSON.AddProperty("description", &description);
&rootJSON.AddProperty("organization", &organization);
&rootJSON.AddProperty("ultraStatus", &ultraStatus);
&rootJSON.AddProperty("allowGuests", &allowGuests);
&rootJSON.AddProperty("allowObservers", &allowObservers);
&rootJSON.AddProperty("closedComplete", &closedComplete);
&rootJSON.AddProperty("availability", &availabilityJSON);
&rootJSON.AddProperty("enrollment", &enrollmentJSON);
&rootJSON.AddProperty("locale", &localeJSON);
&jsonString = &rootJSON.ToString();
/* Set the request body */
&ret1 = &Request_MSG.SetContentString(&jsonString);
/* Send the request */
&Response_MSG = %IntBroker.SyncRequest(&Request_MSG);
If &Response_MSG.ResponseStatus = %IB_Status_Success Then
Local string &jsonRespStr = &Response_MSG.GetContentString();
Local JsonParser &parser = CreateJsonParser();
&ret1 = &parser.Parse(&jsonRespStr);
Local JsonObject &jsonResp = &parser.GetRootObject();
MessageBox(0, "", 0, 0, "" | &jsonRespStr);
End-If;
End-While;
End-If;