Forum Discussion

AishwaryaEA's avatar
3 months ago

Incremental data for attachments in messages and replies

I am trying to get incremental data based on required datetime field for attachments related data in messages and replies. Can someone please help me with this ?

Graphql queries for which I need incremental data is as follows:

query Attachments {
  messages {
    edges {
      node {
        id
        attachments {
          edges {
            node {
              id
              filename
              url
            }
          }
        }
      }
    }
  }
}

Thanks

5 Replies

  • query Attachments {
      messages(constraints: {attachmentsCount: {gt: 0}}) {
        edges {
          node {
            lastPublishTime
          }
        }
      }
    }

    AishwaryaEA not sure if this works
    I don't think attachment has datetime field (maybe I am wrong), but you can use the datetime from the messages / replies maybe?

  • AishwaryaEA's avatar
    AishwaryaEA
    Helper
    3 months ago

    peterluThanks for answering. Actually this one will give me all the data which has any no. of attachment but I wanted to have it incrementally only. I was actually able to modify query, based on conversationLastPostTime constraints, but that is also just giving me 25 records at once rather than giving all incremental records. Please let me know if there is any workaround it. My query:

    query Attachments {
      messages(
        constraints: {conversationLastPostTime: {gte: "2024-06-01T01:47:41.349-08:00", lte: "2024-10-29T13:23:23.074-07:00"}, depth: {eq: 0}}
        last: 1000
      ) {
        edges {
          node {
            id
            attachments {
              edges {
                node {
                  id
                  filename
                  url
                }
              }
            }
          }
        }
      }
    }

  • AishwaryaEAYou are using the dynamic conversationLastPostTime to fetch incremental data. This is the correct solution. Api will only return you 25 records or any number you specify, but there is a max number. To solve this, you need to use pagination method. 
    So first, get a total count of your data. Then use multiple GraphQL query to loop through the pagination. You can use Python or nodejs to achieve this if you are working on a data project. Or you can use frontend JS to loop through the pagination in your customized UI.

     

  • peterluThanks for answering. Actually when I am using conversationLastPostTime filter, it is showing up messages where I am adding attachment incrementally but it is not showing up the actual attachment related details. For e.g.  I added a attachment in the reply section of a message on 2024-10-23. On running below mentioned query, in response, parent message id where we have added attachment in reply is showing up in incremental data but attachment details are still missing. Please let me know if we can modify our query to get the desired result.

    query Attachments {
      messages(
        constraints: {conversationLastPostTime: {gte: "2024-10-21T01:47:41.349-08:00", lte: "2025-10-29T13:23:23.074-07:00"}, depth: {eq: 0}}
        last: 1000
      ) {
        edges {
          node {
            id
            attachments {
              edges {
                node {
                  id
                  filename
                  url
                }
              }
            }
          }
        }
      }
    }

     

    "node": {
                            "id": "message:abc123",
                            "attachments": {
                                "edges": []
                            }
                        }


    Regarding pagination, we have already started working on that, just like how you have suggested. Thanks for the help there.🙂

  • Following up with the previous reply, actually I was able to get attachments incrementally by using below mentioned query, by fetching attachments at descendants replies level. So we are good here. But I noticed 2 things:

    1. Giving kudos to a message or reply is not updating conversationLastPostTime.
    2. Editing a reply is also not updating conversationLastPostTime.

    Can you please guide us on how to get edited message or reply and how to get updated kudos count in incremental data.

    query Replies {
      messages(
        constraints: {conversationLastPostTime: {gte: "2024-10-23T09:04:18.439+01:00", lte: "2025-01-01T00:00:00.000+00:00"}, depth: {eq: 0}}
        last: 1000
      ) {
        edges {
          node {
            id
            descendants {
              edges {
                node {
                  id
                  body
                  board {
                    id
                  }
                  attachments {
                    edges {
                      node {
                        id
                        url
                      }
                    }
                  }
                  author {
                    id
                    login
                  }
                  depth
                  kudos {
                    totalCount
                  }
                  postTime
                  viewHref
                }
              }
            }
          }
        }
        totalCount
      }
    }