在Desire2Learn 10.0中发布新论坛帖子时出现404错误

时间:2012-07-26 17:21:21

标签: desire2learn

我正在使用D2L API,并且遇到一些POST请求有困难。

使用JSON对象执行版本检查(POST):

[{ "ProductCode": "lp", "Version": "1.0" }]

正确返回,为我提供了一个有效的JSON对象作为响应,据说我有信心我的代码发出呼叫是正常的。

但是,当我发布POST以在论坛中创建帖子时,我得到了404响应。我正在为此调用发送的JSON对象是:

[
 {
 "ParentPostId": null,
 "Subject": "API Posted",
 "Message": {
   "Text": "This message has been posted by the API",
   "HTML": "This message has been posted by the API"
   },
 "IsAnonymous": false
 }
]

提交的网址为/d2l/api/le/{ver}/{orgId}/discussions/forums/{forumId}/topics/{topicId}/posts/

我已经使用相同论坛和主题中的帖子的GET验证了ver / orgId / forumId / topicId都是有效的。我也试过单独和同时引用ParentPostId和IsAnonymous的值。

2 个答案:

答案 0 :(得分:1)

http://docs.valence.desire2learn.com/res/discuss.html#post--d2l-api-le-(D2LVERSION-version)-(D2LID-orgUnitId)-discussions-forums-(D2LID-forumId)-topics-(D2LID-topicId)-posts-查看该路线的文档,看起来所需的数据结构使用RichTextInput而不是RichText Message

尝试将Message字段更改为:

{
   "Content": "This message has been posted by the API",
   "Type": "Text"
}

答案 1 :(得分:1)

尝试从JSON中删除方括号。

成功请求和响应的示例如下:

REQUEST  

POST https://valence.desire2learn.com/d2l/api/le/1.0/7664/discussions/forums/203/topics/508/posts/?x_b=TwULqrltMXvTE8utuLCN5O&x_a=L2Hd9WvDTcyiyu5n2AEgpg&x_d=nF61tBeuzd0EPTW7nm8iGc4MB7NeJZaNM2VlzHp0bwU&x_c=I3i_k2aANTIf2X6aFsiOdvlElSR_avvOYnA2ibcWabA&x_t=1343335429 HTTP/1.1
Accept-Encoding: gzip,deflate
Accept: application/json
Content-Type: application/json

 { "ParentPostId": null, "Subject": "API Posted", "Message": { "Content": "This message has been posted by the API", "Type": "HTML" }, "IsAnonymous": false } 


RESPONSE

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Length: 369
Content-Type: application/json; charset=UTF-8
Expires: -1
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Date: Thu, 26 Jul 2012 20:43:58 GMT

{"ForumId":203,"PostId":574,"TopicId":508,"PostingUserId":3667,"ThreadId":205,"ParentPostId":null,"Message":{"Text":"","Html":"This message has been posted by the API"},"Subject":"API Posted","DatePosted":"2012-07-26T20:43:58.920Z","IsAnonymous":false,"RequiresApproval":false,"IsDeleted":false,"LastEditDate":null,"LastEditedBy":null,"CanRate":false,"ReplyPostIds":[]}