Download Documents using REST API and webreport
Comments
-
- go to developer.opentext.com
- Find the rest API docs if it is OT CS(livelink) then find its API document
- Download Postman a tool that is very useful for rest API
- Follow the rest api docs where you will do what the API documentation says on the Postman interface thousands of screenshot examples placed by prior users exist in this forum
- If you did that use the Postman code showing toggle/button to show you code in different languages. Since you said WR I assume you will select XHR/Javascript
- Run your code as WR,if you want to run it standalone select java/C# or anything you are comfortable with.
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.
0 -
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:
- Line 1: The
downloadDocument
closure defines an API, accessible by all HTTP methods. - Line 2: The
path
parameter is extracted from theparams
map. - Lines 3 to 6: The script verifies that the path is defined; if not, it returns an error.
- Line 7: The node is retrieved by its path. It's assumed to be within the main Enterprise volume, although you could implement alternative logic to access different volumes.
- Lines 8 to 11: The script checks that the node exists and that the user has access to it; if not, it returns an error.
- Line 12: The underlying java.io.File, which is nested in the
content.content
variable of the node, is returned. - Lines 17 to 21: The ContentScript is configured to be exposed as an API.
Assuming the ContentScript is named
document-util
, you can download theEnterprise:MyFolder:MyDocument
document using the following URL:/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.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 theOTCSTicket
header.6 - Line 1: The
-
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
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
1 -
what is the type of file you are downloading ? this could be the content of the file
0 -
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();
}
} }0 -
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
0 -
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
0
Categories
- All Categories
- 111 Developer Announcements
- 49 Articles
- 103 General Questions
- 123 IM Services
- 40 OpenText Hackathon
- 31 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 897 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 123 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 1 XM Fax