1

我正在使用 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/

我已经验证了 ver/orgId/forumId/topicId 在同一论坛和主题中使用帖子的 GET 都是有效的。我也尝试过分别引用和统一引用 ParentPostId 和 IsAnonymous 的值。

4

2 回答 2

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-,看起来所需的数据结构使用 aRichTextInput而不是RichTextfor Message

尝试将您的Message字段更改为:

{
   "Content": "This message has been posted by the API",
   "Type": "Text"
}
于 2012-07-26T18:25:19.863 回答
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":[]}
于 2012-07-26T20:49:00.393 回答