REST API discussion_topics anonymous discussions are not showing

Jump to solution
PaulSijpkes
Community Participant

When I create an anonymous discussion, it is not displaying in the response list from the discussion_topics endpoint in the REST API.

The list works for non anonymous discussions.

Is there a work around for this or should I report this as a bug?

EDIT:  I have tested POSTing to the same discussion, which does work, the post is added to the anonymous discussion in Canvas.  Just wondering if others are having this issue?

Anonymous discussion:

Screen Shot 2022-04-27 at 11.25.29 am.png

Non anonymous discussion:

Screen Shot 2022-04-27 at 11.26.46 am.png

Labels (2)
0 Likes
1 Solution
James
Community Champion

@PaulSijpkes 

Do not report this as a bug, it is working as intended. Perhaps not what you intended, but what Canvas intended.

That URL is for the Get a single topic endpoint. To the right of the header is a link to the source code. It's in discussion_topics_api_controller.rb and the function is show.

When you pull up the source code and search for "def show" to find the function, the first line of the code is "return unless is_not_anonymous"

I would say that it is specifically designed to not return any information for an anonymous discussion.

If you click on the 59 (the row number of the return), you get three horizontal dots and one of the options there is to View Git blame. When you follow that, you see that it was added 5 months ago and the comment was "Show 404 on REST API View if Anonymous".

Part of that patch to the source code was to define if_not_anonymous, which appears to be true only when you're using full anonymity.

I cannot find anything in the documentation there about why that decision was made.

It looks like anonymous discussions fall into the category of new features that use GraphQL but are not backported to the REST API. Canvas is moving more and more to GraphQL and would eventually like everyone to use it instead of the REST API.

That explains why it is disabled and you get the 404 error -- the REST API doesn't support anonymous discussions. When I make a post to an anonymous discussion, it uses graphql to send the post. When you load the page, Canvas makes a graphql query to get the posts.

If you're not familiar with GraphQL, you can access an explorer by adding /graphiql at the end of your Canvas instance. You can then play around and see what information is available.

The graphql connection that it uses is the legacyNode and then a type of Discussion. The _id is the discussion ID that you would have if you were able to use the REST API. Then go down about 20 items to find Discussion and you can select the things that you want to get.

Here's an example of what a simple query might look like.

query getDiscussion {
  legacyNode(_id: "78982", type: Discussion) {
    id
    ... on Discussion {
      id
      title
      anonymousState
      discussionType
      requireInitialPost
    }
  }
}

That won't get everything, but the idea of GraphQL is to only get the things that you need. You can use the discussionEntriesConnection to get the posts that people have made.

View solution in original post