404 Posting Content to Desire2Learn

喜欢而已 提交于 2019-12-02 10:48:26

This seems like two different questions, one about the route /d2l/api/le/{ver}/{orgUnitId}/content/root/ and one about the route /d2l/api/le/{ver}/{orgUnitId}/content/modules/{moduleId}/structure/. I'll try to address these separately:

Adding a root module. The first route gets used to add a route module to an org unit's content repository. The route has particular restrictions around the "Title" and "ShortTitle" properties: both must be non-null, and non-empty. In addition, the ShortTitle property must be in a form that can't be "trimmed" down to the empty string (for example, it can't be a string that has nothing but white-space in it). The slightly different restrictions on these strings has been recognized as an inconsistency, and a more regular approach may be forthcoming in a future release. You're safe if you take the approach that you must provide a title and short title for new root modules.

Adding a topic to an existing content structure. The second route gets used to add to an existing module's structure in an org unit's content repository. The way you use the route varies depending on whether you want to add a URL or whether you want to add a file.

To add a topic that's nothing more than URL, you need provide only the first part of the multipart/mixed POST (and in fact, you can just send a single POST body) with the application/json type:

{
   "Title": "Test link topic title",
   "ShortTitle": "Link",
   "Type": 1,
   "TopicType": 3,
   "URL": "http://fqd.url.to.resource.com/",
   "StartDate": null,
   "EndDate": null,
   "IsHidden": false,
   "IsLocked": false
}

Note that: (a) your topic must have a short title--in fact, the topic data block has the same restrictions around Title and ShortTitle properties as in the first question above; and, (b) you don't need to provide a second part containing the URL only.

To add a topic that's a file, you provide a similar JSON block as the first part of your multipart/mixed POST body, but (a) the TopicType should have the value '1' to indicate the topic is a file, (b) the URL property should point to a valid location URL to within the org unit's existing content space (this is how the back-end service knows where to store the file), and (c) the second part of the POST should contain the file data. Your POST body will end up looking something like this:

POST https://yourlms.edu/d2l/api/le/{ver}/{orgUnitId}/content/modules/{moduleId}/structure/?{auth} HTTP/1.1
Content-type: multipart/mixed; boundary=FOO
Content-length: {length}

--FOO
Content-type: application/json
{
   "Title": "Test file topic title",
   "ShortTitle": "File",
   "Type": 1,
   "TopicType": 1,
   "URL": "http://fqd.url.to.resource.com/",
   "StartDate": null,
   "EndDate": null,
   "IsHidden": false,
   "IsLocked": false
}

--FOO
Content-Disposition: form-data; name=""; filename={filename}
Content-Type: {file's content type}

{binary data}

Currently, the Valence reference docs do not clearly distinguish between these two kinds of requests, and they will soon be updated to do so.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!