Search code examples
desire2learn

404 error when posting new forum post in Desire2Learn 10.0


I'm working with the D2L API,and am having difficulty with some POST requests.

Doing a version check (POST) using the JSON object:

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

returns correctly, providing me a valid JSON object in response, that being said I'm confident that my code to issue the call is working correctly.

When I issue a POST to create a post in a forum, however, I get a 404 in response. The JSON object I'm sending for this call is:

[
 {
 "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
 }
]

And the URL submitted to is /d2l/api/le/{ver}/{orgId}/discussions/forums/{forumId}/topics/{topicId}/posts/

I've verified that ver/orgId/forumId/topicId are all valid using a GET of a post in the same forum and topic. I've also tried quoting the values for ParentPostId and IsAnonymous both separately and in unison.


Solution

  • Try removing the square brackets from the JSON.

    An example of a successful request and response follows:

    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":[]}