We have over 4200 stories created over last 2 years in Jira. Now we need to search and download all latest version of word documents out of them. There are 700 word docs with their unique name. So the algorithm would be like searching those 700 documents one by one and finding out what is the last story they were attached to (to find out the latest version) and then downloading that. Repeat the same for remaining documents.
We access Jira in on-premise server.
Please advise how could I do it better in an automated way if any.
I will suggest you start with the API documentation for an issue. You can script it however you prefer. Also, you can look into this article I wrote a while back here. It allows you to get an extract of attachments on your instance in a CSV file format. That will give you a report of all attachments within your instance, then you can continue with a script that will read the report file and download only doc file extension.