Download Documents using REST API and webreport

Options

How to download documents using rest api and webreport, im still new to rest api btw

Comments

  • appuq
    Options
    • 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.

  • appuq
    edited April 16 #4
    Options

    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

  • what is the type of file you are downloading ? this could be the content of the file

  • appuq
    edited April 17 #7
    Options

    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();
    }
    } }

  • Fir16
    Options

    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

  • appuq
    edited April 18 #10
    Options

    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