11 Replies Latest reply on Apr 22, 2014 10:56 PM by dreiswig

    How do I get the root messageID of a discussion using v3 API?


      When I mouse-over the title of a discussion (root message) on our hosted version site, I see a URL similar to https://hostname-v7.hosted.jivesoftware.com/message/32504#32504.  I want to be able to use a similar URL to reference the discussion in my API logic.  If I retrieve the discussion using the v3 API, I find a resource that provides a list of all replies to this discussion, but it does not include the root message.   It is clear that the discussion can be addressed as discussion content and also by a root messageID, but I cannot find any method in the v3 API that will give me the messageID of the root message.  The only work-around that I have found is to get the html of the discussion page and parse the root message id from that, but that is horribly inefficient; there must be a way to get the root messageID of a discussion without parsing a huge block of html.  I even tried looking at the parent of the first reply message, but it points back to the discussion using the discussion id, not to the message using the messageID (all subsequent replies point back using message ids).  Using the discussion id in the URL for the root message is not an option due to constraints of existing code that cannot be changed at this time.

        • Re: How do I get the root messageID of a discussion using v3 API?

          Matt Collinge and Ryan Rutan


          Can you please reply on this?


          Best Regards


          • Re: How do I get the root messageID of a discussion using v3 API?

            I could be mistaken, but I believe the disussion _is_ the root message.  In the first v3 link you posted, the root message is displayed as the content of the discussion element itself.  So, I think you could consider the ID of the discussion to be the ID of the root message.  Does that help?

            • Re: How do I get the root messageID of a discussion using v3 API?

              Dan Reiswig - just wanted to double check that you got the information that you needed good/bad/other.  Let me know if there is anything more we can do to help.

                • Re: How do I get the root messageID of a discussion using v3 API?

                  To Ryan and the others who responded, thank you, I appreciate the information.


                  Now please forgive me, I am going to ...



                  My application is not a conversion application, it is an integration with another highly-visible corporate application.  Within the context of the application, the integration dynamically displays a Jive threaded discussion as a nicely formatted, properly indented list of messages and replies, including links to add a reply at any point in the tree, similar to what you see on this page, plus links to traverse upwards to easily see proper context in long discussions.  Using the v1 API, where every message can be identified by a message id (including the root message), the output of the entire thread is generated by an 11-line recursive function.  Call it with the root message id, it displays the message with appropriate links and indentation, finds all immediate children and calls itself -- done.  Simple, elegant, even beautiful. 


                  Now, with the v3 API, the root of my tree is a completely different object type with a different addressing scheme.  I can display it with one block of code, but then I need a different block of code to handle each of the replies.  The links to create a reply need to know which kind of object it is dealing with to do that job properly (is the parent a message or a thread?).  The code that generates the links to go back up the tree need to determine if this is the first-level reply with a thread parent or a deeper level reply with a message parent, because the link URL is completely different.  My 11-line recursive function is now over 150 lines of spaghetti (I have not actually written it yet, so this might be an exaggeration, it might really be only 140 lines of spaghetti).


                  The code used in the Jive software does not have this problem.  The URL shown when you mouse over the title of the root message on a discussion page uses the message id, not the thread id -- try it at top of this page.  I am willing to bet that this is because the function that generates this page is an elegant, recursive function.  Of course the Jive programmers are not limited to using the REST API to get data, so this is not a problem for them.  I heard Mark Weitzel and others at JiveWorld say that one of the goals for the API is that we would be able to do everything that the client can do using it.  I understand that is a very lofty goal and may not be 100% possible.  Here is an example where that goal is not met:  I cannot generate that URL with the message id using the v3 REST API.


                  I can deal with this, I can write that 150-line function and if it is absolutely necessary, I will.  But I think it is a real shame to lose such elegance because one little id is not available.



                  Thank you for your time, now get back to work improving the REST API!

                    • Re: How do I get the root messageID of a discussion using v3 API?

                      Dan, the team has taken in your feedback, and ironically..the shift away from the v1/v2 versions was due to excessive confusion over the concept of a root message.  While I cannot guarantee that these changes will be made, we have filed a JIRA improvement against the API to be considered in future versions.  I want to make sure that I get your recommendations correct, so this is what I've put into the JIRA, let me know if you would like to change it in any way.

                      • For messages, the desire for a "parent message" resource to always be a message, rather than a possible discussion type.
                      • For messages, the desire for a "root message" resource that exposes the top-most message in a thread.
                      • update documentation Jive REST Rest API v3.6 → Message entity to be more clear about the type/detection of the parent field
                        • Re: How do I get the root messageID of a discussion using v3 API?

                          Thank you Ryan,


                          The ability to identify and link to the root message by message id as you described would resolve this issue in my opinion.  I understand there are no promises, but I appreciate that the team has considered my request.  Overall, I am very happy with the new API.  So far, I have had very little trouble converting our old V1 code to the new V3 API and that earns kudos to the team.


                          I have spent some time thinking about this.  I will take this opportunity, based on your request for feedback, to describe an example solution that would work for me.


                          First, if I was on the team, I would not allow any change that might break existing code based on existing documentation.  Second, I would want any additions to be as unobtrusive as possible because this is a solution for an edge case.


                          The first change that I would suggest is to add a field in the message structure, perhaps called parentMessage, which is a URL that always uses the message id addressing method to reference the parent message, even when the parent message is in the discussion thread itself.


                          message structure ...
                          "parentMessage": "https://community.jivesoftware.com/api/core/v3/messages/1450633",
                          ... message structure


                          This would actually be the same value as the existing "parent" field in the message structure except for the case when the message is a first-level reply and the parent is the discussion thread.


                          I believe that if I had this one change, I could accomplish what I want to do with messages.  I could follow the links up the tree to the root message and get the id that way if necessary.  My recursive solution would require a bit of pre-processing to fill-in the tree, but that is acceptable.


                          To simplify getting the root message id, it would be nice, but not entirely necessary, to add that value to the discussion structure.  If you added a field, perhaps called rootMessageId, to the discussion structure, it could identify the message that is embedded in the discussion structure by its message id.


                          discussion structure ...
                          "rootMessageId": "1450644",
                          ... discussion structure


                          Again, this is not entirely necessary, but it would make building the tree for recursion a bit easier.


                          Obviously, I do not know the internal code or structures, nor am I familiar with all of your design goals, so I expect your solution will be different for very good reasons.  I am providing these examples because I think this is a good way to describe a specific solution that would allow me to accomplish what I would like to do with the API.


                          Thank you again for your consideration.