1
votes

Using D2L Rest API Sending following block for creating topic inside already existing forum:

URL: POST /d2l/api/le/(D2LVERSION: version)/(D2LID: orgUnitId)/discussions/forums/(D2LID: forumId)/topics/

{
    "Name" : "Test Forum API",
    "Description" : {
        "Text" : "",
        "Html" : "Test"
    },
    "AllowAnonymousPosts" : true,
    "StartDate" : null,
    "EndDate" : null,
    "IsHidden" : false,
    "UnlockStartDate" : null,
    "UnlockEndDate" : null,
    "RequiresApproval" : false,
    "ScoreOutOf" : null,
    "IsAutoScore" : true,
    "IncludeNonScoredValues" : true,
    "ScoringType" : null,
    "IsLocked" : false,
    "MustPostToParticipate" : true
}

Getting error: INFO: Redirect requested but followRedirects is disabled Status Code 302 Object moved to /d2l/error/404

2

2 Answers

0
votes

Post and Redirect don't work together. Often environments (a loadbalancer or other network component) will automatically redirect all http operations to https. Then your client library won't actually follow the 302.

You probably want to use https if it is enabled, and you can make the D2L Libraries produce https urls.

(You may also want to have your client http library you are using follow redirects though because there are scenarios where the GET operations might get redirected)

0
votes

Note that the CreateTopicData structure that you must pass the API to create a new topic does not use a RichText composite structure for the Description property on input. Instead, you must use a RichTextInput composite structure, which is slightly different:

{
    "Name" : "Test Forum API",
    "Description" : {
        "Content" : "Test",
        "Type": "HTML"
    },
    ...
}

The API will pass back a RichText structure on output, however.

Using our test service, with a POST to an URL like this (assuming an org ID of 8083, and a forum ID of 4174)

https://myLMShost.edu/d2l/api/le/1.0/8083/discussions/forums/4174/topics/

we passed in a JSON structure that looks like this:

{'AllowAnonymousPosts': True,
 'Description': {'Content': 'test', 'Type': 'HTML'},
 'EndDate': None,
 'IncludeNonScoredValues': False,
 'IsAutoScore': True,
 'IsHidden': False,
 'IsLocked': False,
 'MustPostToParticipate': True,
 'Name': 'Test Forum API',
 'RequiresApproval': False,
 'ScoreOutOf': None,
 'ScoringType': None,
 'StartDate': None,
 'UnlockEndDate': None,
 'UnlockStartDate': None}

And our test service returned the new topic post, like this:

{'AllowAnonymousPosts': True,
 'Description': {'Html': 'test', 'Text': ''},
 'EndDate': None,
 'ForumId': 4174,
 'IncludeNonScoredValues': False,
 'IsAutoScore': True,
 'IsHidden': False,
 'IsLocked': False,
 'MustPostToParticipate': True,
 'Name': 'Test Forum API',
 'PinnedPostCount': 0,
 'RatingsCount': 0,
 'RatingsSum': 0,
 'RequiresApproval': False,
 'ScoreOutOf': None,
 'ScoredCount': 0,
 'ScoringType': None,
 'StartDate': None,
 'TopicId': 88569,
 'UnapprovedPostCount': 0,
 'UnlockEndDate': None,
 'UnlockStartDate': None}