Authentication REST API call from C# or Java
Comments
-
Here is an example that makes use of OTDS token https://knowledge.opentext.com/knowledge/llisapi.dll?func=ll&objId=61382047&objAction=viewincontainer the theory is once you get a authtoken then any call in livelink webgui can be done using the token the example shows how to use the ?func=search which is the searchAPI I am also thinking that RESTAPI can be called just within the realm of content server as well
0 -
Complete source code of a C# command-line application for .NET 4.0 using the CS REST API to authenticate and print the user identifier of the authenticated user:
using System; using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Formatting; using System.Net.Http.Headers; using System.Runtime.Serialization; using System.Threading.Tasks; namespace LivelinkRestTest { // Describe response of POST .../api/v1/auth [DataContract] struct Authentication { [DataMember(Name = "ticket")] public string Ticket { get; set; } } // Describe response of GET .../api/v1/auth struct User { public struct UserData { [DataMember(Name = "id")] public string ID { get; set; } // Add other properties here if you need them } [DataMember(Name = "data")] public UserData Data; } class Program { // Livelink CGI URL with the trailing slash const string ServerUrl = "http://vmfp-oclipse.opentext.net/carbonfibre/cs/"; // Username and password with the login privilege const string UserName = "..."; const string Password = "..."; static void Main(string[] args) { try { Run().Wait(); } catch (HttpRequestException exception) { Console.WriteLine(exception.ToString()); } } static async Task Run() { var ticket = await GetTicket(); var user = await GetUser(ticket); Console.WriteLine("Authenticated as user " + user.Data.ID + "."); } static HttpClient GetHttpClient() { var client = new HttpClient(); client.BaseAddress = new Uri(Program.ServerUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); return client; } static async Task<string> GetTicket() { using (var client = GetHttpClient()) { var parameters = new List<KeyValuePair<string, string>>(); parameters.Add(new KeyValuePair<string, string>( "username", Program.UserName)); parameters.Add(new KeyValuePair<string, string>( "password", Program.Password)); var response = await client.PostAsync("api/v1/auth", new FormUrlEncodedContent(parameters)); response.EnsureSuccessStatusCode(); Authentication authentication = await response.Content.ReadAsAsync<Authentication>(); return authentication.Ticket; } } static async Task<User> GetUser(string ticket) { using (var client = GetHttpClient()) { client.DefaultRequestHeaders.Add("OTCSTicket", ticket); HttpResponseMessage response = await client.GetAsync("api/v1/auth"); response.EnsureSuccessStatusCode(); return await response.Content.ReadAsAsync<User>(); } } } }
It is not possible to create a Binder using the CS REST API yet. It should be possible using the SOAP WS. If you use xECM, a Business Workspace can be created by the CS REST API.
Appu, although the CS XML Search API (?func=search&format=xml&...) can be used like a REST API returning an XML response, it is not a part of the CS REST API. The CS XML Search API is a CS web request handler authenticated by LLCookie or other cookie accepted by the CS. The CS REST API is authenticated by a custom header (Authorization, OTCSTicket, OTDSTicket etc.) and ignores any cookie if set.
0 -
Hi Ferdinand,
Thanks for the info. It is possible to create a Binder using the REST API. The code is listed below
public string createBinder(string token, string binderName)
{
string nodeid = "";
string contentURL = "http://innovate/otcs/llisapi.dll/api/v1/doctemplates/184422/instances";
string payload = "parent_id=180462&classification_id=180463&name=OpenText Dynamics";byte[] byteArray = Encoding.UTF8.GetBytes(payload); var request = (HttpWebRequest)HttpWebRequest.Create(contentURL); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; request.Headers.Add("OTCSTICKET", token); CookieContainer cookieContainer = new CookieContainer(); // send payload data to server using (var stream = request.GetRequestStream()) { stream.Write(byteArray, 0, byteArray.Length); } //get HTTP response using (var response = (HttpWebResponse)request.GetResponse()) { var responseValue = string.Empty; if (response.StatusCode != HttpStatusCode.OK) { var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode); throw new ApplicationException(message); } String json = new StreamReader(response.GetResponseStream()).ReadToEnd(); // extract token from JSON. We have used a custom class to serialize a JSON var serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] { new DynamicJsonConverter() }); dynamic obj = serializer.Deserialize(json, typeof(object)); nodeid = Convert.ToString( obj.node_id); } return nodeid; }
Glen
0
Categories
- All Categories
- 123 Developer Announcements
- 54 Articles
- 157 General Questions
- 152 Thrust Services
- 56 Developer Hackathon
- 38 Thrust Studio
- 20.6K Analytics
- 4.2K AppWorks
- 9.1K Extended ECM
- 919 Core Messaging
- 84 Digital Asset Management
- 9.4K Documentum
- 34 eDOCS
- 193 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 10 XM Fax
- Follow Categories