REST API and Content Server

Options

Hi,

Trying to execute a simple example in Content Server 10 (Update 13). See attached.

Authentication part seems to work, at least I get a ticket returned, but listing node doesn't work - I get some kind of authorization error in return

enter image description here

Tagged:

Comments

  • Ferdinand Prantl
    Ferdinand Prantl E Community Moderator
    Options

    You're just one character far from the success :-) The problem is in the authorization header name. You're not talking to OTDS, but to OTCS. Instead of otDsticket:

    headers: {"otdsticket": ticket}
    

    try otCsticket (OpenText Content Server TICKET):

    headers: {"otcsticket": ticket}
    

    You could use the OTDSTicket too if you have already authenticated to the OTDS, but saying more authentication possibilities would be rather a theme for a complete new article.

    A hint for your future productive code: if you want get the Enterprise Volume information, get it by its subtype: /volumes/141. It can have a different nodeid than the default 2000.

    I hope that you'll find the REST API easy to use. Good luck!

  • Hi Ferdinand,

    Thanks for a quick answer.

    Tried changing parameter as you suggested but it still doesn't work. I get the same response.

    See attached

    enter image description here

  • Ferdinand Prantl
    Ferdinand Prantl E Community Moderator
    Options

    I tried your code with almost no changes and it worked. The only thing I had to fix was consuming the response from /auth. It came as JSON already; actually, the extra parsing step which you have there threw an error:

    <!DOCTYPE html>
    <html>
      <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
          var url = "//myserver/livelink/llisapi.dll/api/v1";
          var credentials = { userName: "Admin", password: "livelink" };
    
          $.post(url + "/auth", credentials, function (response) {
            var ticket = response.ticket;
            $.ajax({
              type: "GET", url: url + "/nodes/2000",
              headers: { "otcsticket": ticket },
              dataType: "json",
              success: function (response) {
                alert(response.data.name);
              }
            })
          });
        </script>
      </head>
      <body></body>
    </html>
    

    How does your ticket look like? It should be something like "q1B9zg4Cl3E3Ks3lH+zXxA0fPoicjLlUCWMo45MOWCt4LB7cq0xn8Wt04Y5cdLA0", for example. You could also check the CS logs if they say more about why the athentication for the particular request handler failed.

  • Yo Uldis,
    I think the problem is your path.

    I'm connecting to a different CGI. My url:
    http:///OTCS/livelink.exe/api/v1/

    So I think you're looking for these:

    http://XXXXX/livelink.exe/api/v1/auth

    http://XXXXX/livelink.exe/api/v1/nodes/2000

    And then if that helps, checkout:

    http://XXXXX/livelink.exe/api/v1/volumes/141/nodes

    Also, I installed a REST debugger client in Chrome and used that for debugging. That way I can make a connection and pull the JSON object.

    Cheers

  • Now I'm trying to get Ferdinan's example working (since it's simpler)

    <script>
      var url = "//83.142.96.202/csdev2/llisapi.dll/api/v1";
      var credentials = { userName: "Admin", password: "livelink" };
    
      $.post(url + "/auth", credentials, function (response) {
        var ticket = JSON.parse(response).ticket;
    alert(ticket);
        $.ajax({
          type: "GET", url: url + "/nodes/2000",
          headers: { "otcsticket": ticket },
          dataType: "json",
          success: function (response) {
            alert(response.data.name);
          }
        })
      });
    

    In my case I don't get JSON from /auth. I have to parse it and then I get ticket in the format as you described.

    BUT I still get error when calling /nodes.

    I looked in logs and found these lines.

    01/29/2014 12:23:43 Check HTTP Referer has been disabled for the RestAPI since it does not make sense.
    01/29/2014 12:23:43 Dispatcher error: Authentication Required
    

    btw - I'm running these tests from a blank WebReport within Content Server. If this makes some difference

    Any ideas?

    Uldis

  • ..

  • guys, any help?

  • Ferdinand Prantl
    Ferdinand Prantl E Community Moderator
    Options

    Sorry for the delay; I hope that the new version of this forum with reply notifications will be released soon...

    Can you check that the OTCSTicket is really included in the request? By Fiddler, in the developer tools or in the server log. The only case of rejected ticket I saw when getting LLCookie by LAPI and using it for WS, when ELIB was installed with the CS, because it breaks the CS authentication. I have also just CS + WebReports and some optional modules.

    Which jQuery version do you use? I wonder why I get the already parsed JSON and you don't. The dataType: "json" shouldn't be necessary, because the server responds with the ContentType: application/json, but it doesn't disturb either.

  • Hi Ferdinand,

    I can't see OTCSTicket in request (/nodes/2000) header.

    My jquery version - /core/jquery-1.3.2.min.js

    Uldis

  • btw - in parallel I'm testing UI Widgets (/csui/csui.js) and in combination with /auth ticket it works fine.

    See below:

    $(document).ready(function()
    

    {
    var urlpref="http://83.142.96.202/csdev2/llisapi.dll";
    var supportdir = "http://83.142.96.202/imgcsd2/";
    var ticket;

    $.post(urlpref+"/api/v1/auth",
    {
        username:"Admin",
        password:"livelink"
    }, function(data,status)
    {
        data = JSON.parse(data)
        ticket = data.ticket;
    
        csui.require(["util/connector", "util/authenticator", "model/node", "widget/propertiesdialog", "widget/folderbrowser", "view/html"],
        function (Connector, Authenticator, NodeModel, PropertiesDialogWidget, FolderBrowserWidget,HtmlView) 
        {
    
            b = new FolderBrowserWidget({
                    placeholder: "#browser",
                    connection: { 
                        url: urlpref+"/api/v1/",supportPath: supportdir,
                    session: {ticket:ticket}
                    }
                });
    
            b.display();
    
        }); 
    
    });
    

    });

  • Got it!

    Had to add "beforesend". Although I'm not sure why it works for you just like that..

    $.ajax({ 
            type: "GET", 
            url: urlpref+"/api/v1/volumes/141/nodes",
            headers: {"OTCSTicket": ticket},
            dataType: "text", 
            beforeSend: function (request)
            {
                request.setRequestHeader("OTCSTicket", ticket);
            },
            success: function(resp)
            { 
                // we have the response 
                alert(resp); 
            }, 
            error: function(e)
            { 
                var ttt = e;
                alert('Error: ' + e); 
            } 
            });
    
  • Ferdinand Prantl
    Ferdinand Prantl E Community Moderator
    Options

    I see that you nailed it, congratulations!

    Not seeing the OTCSTicket header among the /nodes/2000 request headers means that your code headers: { "otcsticket": ticket } had no effect. Your version of jQuery didn't support this property in the $.ajax parameters and just ignored it.

    Your jQuery version is ancient; you should upgrade at least to 1.6 to have the current AJAX interface. If you must retain that version, you were right to reach to another way - before the jQuery calls xhr.send(), set the headers on the xhr object on your own. The beforeSend callback allows you doing anything before the request gets executed and you can manipulate the XMLHttpRequest used by jQuery as you wish. Newer versions of jQuery offer for convenience properties for the typical usage scenarios, like setting headers by the headers property.

  • Ferdinand Prantl
    Ferdinand Prantl E Community Moderator
    Options

    I see that you learnt about the CS UI Widgets already. The just released (first) 10.0.0 version uses the jQuery 1.10.2 and you found that they work, of course :-)

    The Widgets internally abstract from the the REST API calls by using Backbone models and collections. It is not clear whether and how these could be shared with developers outside OT; currently, we intend to publish only the objects from the widget/... modules. They have an easy-to-use interface for the most common scenarios and we can guarantee their interface independently on which framework we'd use underneath. However, if they were publicly documented you'd get support for authentication and for non-HTML5 browsers (IE8-9) without having every developer writing it again. There's been an idea about this posted here. For example, this would be the code using the Widgets for your scenario:

    csui.require(["util/connector", "model/node"],
    function (Connector, NodeModel) {
      var connector = new Connector({
            connection: {
              url: "//localhost/otcs/cs/api/v1",
              supportPath: "/otcssupport"
            }
          }),
          node = new NodeModel({ id: 2000 }, { connector: connector });
      node.fetch({
        success: function () {
          alert(node.get("name"));
        }
      });
    });
    

    However, this uses the Backbone interface and if decided to leave Backbone in the next version, it would break your code. It's difficult to commit to a stable interface when the web browser technology is developing so rapidly. That's why the reluctance to publish more than necessary.

  • Thanks Ferdinand! I will do some more testing..

  • Hi Uldis, How did you deploy your simple script.

    $.ajax({ 
            type: "GET", 
            url: urlpref+"/api/v1/volumes/141/nodes",
            headers: {"OTCSTicket": ticket},
            dataType: "text", 
            beforeSend: function (request)
            {
                request.setRequestHeader("OTCSTicket", ticket);
            },
            success: function(resp)
            { 
                // we have the response 
                alert(resp); 
            }, 
            error: function(e)
            { 
                var ttt = e;
                alert('Error: ' + e); 
            } 
            });
    

    Is it as simple as creating a new HTML page & then adding a HTML button & javasctipt function to it? Please Explain.

  • Uldis, Another simple question. What version of jquery did you use to make the above script work?

    Thank You
    Vijhay D

  • Hi,

    yes, just create simple HTML file locally and include the code.

    You can reference any jquery version (e.g. 1.6)

    I've also tested this within a Content Server environment, added code inside a WebReport.

    Uldis