How to download documents using rest api and webreport, im still new to rest api btw
PS: WR is an OTCS tool that allows you to use a tag language in CS. By using it in the above method all you are doing is relegating that to give you an HTML form that sits inside CS. One of the benefits you may get is since it is a WR you will get the authentication token from that page itself.
WebReport approach
Let's imagine you are searching for documents within a folder and want to enable the option to download them. First, you need to prepare the LiveReport, which will serve as the source for the WebReport. If, for example, you're searching within a folder with DataID=133428, you should use the following query:
SELECT name, dataid FROM dtree WHERE subtype=144 AND parentid=133428
Once you have the source ready, you can proceed to set up the WebReport. Use the "LLURL:DOWNLOAD" subtag to generate the code necessary for the download function. Below is the code for the WebReport:
[LL_WEBREPORT_STARTROW /] <table> <tr> <td><a href="[LL_REPTAG_2 LLURL:DOWNLOAD /]">[LL_REPTAG_1 /]</a></td> </tr> </table> [LL_WEBREPORT_ENDROW /]
The result would be a clickable list of documents.
ModuleSuite approach
If you have the ModuleSuite installed, you can create your own API to facilitate document downloads. The typical method involves creating a ContentScript in the "Content Script Volume:CSServices" folder. When correctly programmed, this script can be used to expose APIs.
Below is an example of how to implement this:
The relevant parts of the snippet are as follows:
downloadDocument
path
params
content.content
Assuming the ContentScript is named document-util, you can download the Enterprise:MyFolder:MyDocument document using the following URL: /amcsapi/document-util/downloadDocument?path=MyFolder:MyDocument
document-util
Enterprise:MyFolder:MyDocument
/amcsapi/document-util/downloadDocument?path=MyFolder:MyDocument
Please note that this URL will function properly as long as you include a valid LLCookie with your request to authenticate the logged-in user; hence, it is particularly suited for browser-based invocations.
LLCookie
If you prefer a completely programmatic approach, you should first obtain a valid token by authenticating through the standard API. Then, you can invoke the URL /amcsapi/v1/document-util/downloadDocument?path=MyFolder:MyDocument, setting the token as the OTCSTicket header.
/amcsapi/v1/document-util/downloadDocument?path=MyFolder:MyDocument
OTCSTicket
Since we are talking custom code in WR a long time back a user(not me) created a custom WR tag that allows download to the server . It is kind of buried in old development forums
@GregPetti who developed WR has good documentation on how to do this custom tag correctly
https://www.ravenblackts.com/about-us
Livelink also has an object called Collections, you can add the documents to a collection manually using WR and you can download collections as well.
if you put this code in a CS server note this goes into new servers here
<OTHOME>\appData\webreports\subtags
What the txt file code is showing is Oscript:)
another one is the
https://knowledge.opentext.com/knowledge/llisapi.dll?func=ll&objId=76455857&objAction=viewincontainer&ShowReplyEntry=76980600#forum_topic_76980600
sorry but im getting this, not sure why
what is the type of file you are downloading ? this could be the content of the file
if you put a file with this line Hello World you will get that, what you are getting is the content of the file so it a DOCX it will do an octet-stream. What programmers do is receive the content in a file system. When you see that crazy binary info look where the Postman response panel says and the ellipsis you will see "Save Response to file" .You will have to use some language that knows how to work that into an actual file in a program.
Look in this forum for an OT Person called Ferdinand Prandtl he is one of the earliest OT programmers who used to support us all in here . You should see Javascript examples that will help you
this might also be a good candidate to ask "chatGPT" You would show CHATGPT the JS code and ask its suggestions to burn it into the file system :)
I tried it in chatgpt and for what it's worth it worked for me:).Here are a few things to help you if you load it as a simple file on your desktop then that browser will throw a CORS error so I put this file in the same server as my livelink server so that the origin and cross are the same…Firefox ran the command and I go the file in my downloads directory.Obviously browsers can't access file systems so I would use some programming avenue to get around that limitation. I did not try the java code it suggested:)
<script> var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.responseType = 'blob'; // Set the responseType to blob xhr.addEventListener("readystatechange", function() { if(this.readyState === 4) { if (this.status === 200) { var blob = this.response; var fileName = "appukuttan.docx"; // Set the desired file name var a = document.createElement('a'); a.href = window.URL.createObjectURL(blob); a.download = fileName; document.body.appendChild(a); a.click(); document.body.removeChild(a); } else { console.error('Request failed with status', this.status); } } }); xhr.open("GET", "http://myserver:8080/otcs/cs.exe/api/v1/nodes/1598601/content"); xhr.setRequestHeader("otdsticket", "*OTDSSSO*"); // WARNING: Cookies will be stripped away by the browser before sending the request. xhr.setRequestHeader("Cookie", "LLCookie=38e4141216463b7dac7329d4efd0e268a7ae55ee5f5376402a311b973030fe8161c992dab8f18ae89407cfd648951998567225f990a9169fb3d12b176aa4db40; LLTZCookie=0"); xhr.send(); </script>
import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class FileDownloader { public static void main(String[] args) { String urlStr = "http://myserver:8080/otcs/cs.exe/api/v1/nodes/1598601/content"; String otdsTicket = "YOUR_OTDS_TICKET_HERE"; // Replace with your actual OTDS ticket String fileName = "file_name_here"; // Set the desired file name an actual path perhaps :) try { URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("otdsticket", otdsTicket); conn.setRequestProperty("Cookie", "LLCookie=38e4141216463b7dac7329d4efd0e268a7ae55ee5f5376402a311b973030fe8161c992dab8f18ae89407cfd648951998567225f990a9169fb3d12b176aa4db40; LLTZCookie=0"); conn.setRequestMethod("GET"); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { InputStream inputStream = conn.getInputStream(); Path filePath = Paths.get(fileName); Files.copy(inputStream, filePath); System.out.println("File downloaded successfully!"); } else { System.out.println("Failed to download file. Response code: " + conn.getResponseCode()); } conn.disconnect(); } catch (IOException e) { e.printStackTrace(); } } }
i'm downloading documents, the requirement was to download documents from content server to local storage.
if you are downloading a document then what you see in the view could be the document itself represented as best Postman can, just like opening it in Notepad
The code you finally write should be in some REST API invokable language as you see from the two examples I posted it can be done in pure javascript which is not a traditional server side. You could write this as a nodejs application if you needed to. Finally, REST API is not language-dependent it is just a protocol by which you query and exchange data so the logic will be up to you.
a good read https://medium.com/extend/what-is-rest-a-simple-explanation-for-beginners-part-1-introduction-b4a072f8740f