Public API - how do I retrieve list of comments along w/ object the comment relates to?

Asking for a friend, is there a way to get a list of the comments on a workspace and the element they are linked to through the Bluescape public API?

Users can leave comments on workspace elements, and you can programmatically query elements to get comments, or write new comments on workspace elements.

In order to get comments in elements in a workspace, you will need to query the specific workspace to find the elements in the workspace.

This easily done with graphQL by using our graphQL playground to view the documentation in the docs tab.

Here is an example of documentation for elements.shape.comments to get the comments for a shape

An example graphQL query to get comments for all elements in a workspace:

query getElementsComments{
    elements(workspaceId: "IPvtDuI2Eh7DAdsI6ciu") { 
      __typename
      elementId:id
      comments{
          commenterName
          createdAt
          id
          text
      }
    }
}

Sample response:

{
    "data": {
        "elements": [
            {
                "__typename": "Text",
                "elementId": "6466901110163c060883a653",
                "comments": []
            },
            {
                "__typename": "Shape",
                "elementId": "6466918210163c060883a666",
                "comments": [
                    {
                        "commenterName": "Kevin Koechley",
                        "createdAt": "2023-05-19T00:02:36.074Z",
                        "id": "6466bc9c24c6a204e1833c22",
                        "text": "this is a comment"
                    }
                ]
            }
        ]
    }
}

You can also only return elements by type instead of all element types.

For example, only return Shape elements:

query getElementsComments{
    elements(workspaceId: "IPvtDuI2Eh7DAdsI6ciu") {
        #only return data about shape elements
        ... on Shape{
            __typename
            shapeId:id
            comments{
                commenterName
                createdAt
                id
                text
            }
        }
    }
}

Sample Response:

{
    "data": {
        "elements": [
            {
                "__typename": "Shape",
                "shapeId": "6466918210163c060883a666",
                "comments": [
                    {
                        "commenterName": "Kevin Koechley",
                        "createdAt": "2023-05-19T00:02:36.074Z",
                        "id": "6466bc9c24c6a204e1833c22",
                        "text": "this is a comment"
                    }
                ]
            }
        ]
    }
}

You can also use the elements REST query using our API reference for Elements list v3/workspaces/{workspace}elements endpoint

I hope this helps!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.