Perceptive Content Integration API - Get Information on Objects

This article demonstrates how a custom application can get information on objects from the Perceptive Content Integration API through a few code examples. Always open a session before calling the Integration API and close it afterwards (https://kb.wisc.edu/ecms/102520). These are just a few common examples and all calls are detailed in the Integration Server documentation (https://docs.hyland.com/Developer/IS/en_US/7.4/operations.html). This example comes from an asynchronous .Net WebAPI written in C#.

Perceptive Content Integration Server Documentation

Get Information on Objects

private static string BaseURL = "https://test.imaging.wisc.edu/integrationserver/";
private static HttpClient client = new HttpClient();

/// <summary>
/// Helper for making a GET request to Integration Server API 
/// </summary>
/// <param name="url">URL for this request</param>
private static async Task<string> GetRequest(string url)
{
    try
    {
        //http client data persists so first we clear headers
        client.DefaultRequestHeaders.Clear();

        //Integration API will default to returning XML if we do not 
        //specify the Accept header
        client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

        //Retrieve the access token from memory and 
        //add it to the request as a custom header
        client.DefaultRequestHeaders.Add("X-IntegrationServer-Session-Hash", Token);

        //Send the GET request
        HttpResponseMessage response = await client.GetAsync(url);

        //throws exception if not success
        response.EnsureSuccessStatusCode();

        //Read the response text and return it
        string responseBody = await response.Content.ReadAsStringAsync();
        return responseBody;

    }
    catch (Exception ex)
    {
        //Always close session on fail
        await CloseSession();

        throw;
    }
}

/// <summary>
/// Helper for making a POST request to Integration Server API
/// </summary>
/// <param name="url">URL for this request</param>
/// <param name="postData">Data payload for this request, defaults to empty string</param>
private static async Task<string> PostRequest(string url, string postData = "") //post data defaults to null
{
    try
    {
        //http client data persists so first we clear headers
        client.DefaultRequestHeaders.Clear();

        //API will default to returning XML if we do not 
        //specify the Accept header
        client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

        //Retrieve the access token from memory and 
        //add it to the request as a custom header
        client.DefaultRequestHeaders.Add("X-IntegrationServer-Session-Hash", Token);

        //This line adds the post data and sets the content-type 
        //header to application/json
        var data = new StringContent(postData, Encoding.UTF8, "application/json");

        //Send the POST2 request
        HttpResponseMessage response = await client.PostAsync(url, data);

        //throws exception if not a success
        response.EnsureSuccessStatusCode();

        //Read the response text and return it
        string responseBody = await response.Content.ReadAsStringAsync();

        return responseBody;

    }
    catch (Exception e) //if anything goes wrong end the session
    {
        await CloseSession();
        throw;
    }
}

/// <summary>
/// Gets all drawers stored in the server that the user has some privilege to
/// 
/// https://docs.hyland.com/Developer/IS/en_US/7.4/operations.html#call_Drawer_V2_GET-drawer
/// </summary>
public static async Task<DrawersRoot> GetDrawers()
{
    //Get the drawers
    string retval = await GetRequest(BaseURL + "drawer");

    //parse the JSON to object
    DrawersRoot json = JsonConvert.DeserializeObject<DrawersRoot>(retval);

    return json;
}
 
/// <summary>
/// Gets the folders and documents contained in the drawer
/// 
/// https://docs.hyland.com/Developer/IS/en_US/7.4/operations.html#call_Drawer_V2_GET-drawer-id-content
/// </summary>
/// <param name="DrawerID">ID field of desired drawer</param>
public static async Task<DrawerContent> GetDrawerContent(string DrawerID)
{
    //Get the drawer content, base call did not work - must specify v2
    string retval = await GetRequest(BaseURL + $"v2/drawer/{DrawerID}/content");

    //parse the JSON to object
    DrawerContent json = JsonConvert.DeserializeObject<DrawerContent>(retval);  //parse the JSON to object

    return json;
}

/// <summary>
/// Gets all views in the server.  Includes user priveleges
/// 
/// https://docs.hyland.com/Developer/IS/en_US/7.4/operations.html#call_View_V4_GET-view
/// </summary>
public static async Task<ViewRoot> Views()
{
    // Get all views data
    var retval = await GetRequest(BaseURL + $"view/");

    //parse the JSON to object
    ViewRoot json = JsonConvert.DeserializeObject<ViewRoot>(retval);  

    return json;
}


/// <summary>
/// Run View with type and id in the server. Returns the result of given view in the form of JSON
/// 
/// https://docs.hyland.com/Developer/IS/en_US/7.4/operations.html#call_View_V1_POST-view-id-result
/// </summary>
/// <param name="ViewID">ID field of the desired View</param>
public static async Task<View> GetViewJSON(string ViewID)
{
    //Get specified vew from, note the category query string parameter which is required,
    //and that this is a POST request
    var json = await PostRequest(BaseURL + $"view/{ViewID}/result?category=document");
    return json;

    return root;
}

/// <summary>
/// Gets the document information from the server that matches the ID. Includes 'Send to ShareBase' privilege information. 
/// 
/// https://docs.hyland.com/Developer/IS/en_US/7.4/operations.html#call_Document_V8_GET-document-id
/// </summary>
/// <param name="docID">ID field of the desired document</param>
/// <returns></returns>
public static async Task<Document> GetDocument(string docID)
{
    //Get the document metadata
    var retval = await GetRequest(BaseURL + $"document/{docID}");

    //Parse the JSON to object
    Document json = JsonConvert.DeserializeObject<Document>(retval);  //parse the JSON to object

    return json;
}

/// <summary>
/// Get all workflow queues stored in the server
/// 
/// https://docs.hyland.com/Developer/IS/en_US/7.4/operations.html#call_WorkflowQueue_V2_GET-workflowQueue-
/// </summary>
public static async Task<WorkflowQueueRoot> GetWorkflowQueues()
{
    //Get the workflow queue data
    var retval = await GetRequest(BaseURL + "workflowQueue");

    //Parse the JSON to object
    WorkflowQueueRoot json = JsonConvert.DeserializeObject<WorkflowQueueRoot>(retval);  //parse the JSON to object

    return json;
}

/// <summary>
/// Gets properties of the workflow queue stored in the server. This version returns key attributes and privileges.
/// 
/// https://docs.hyland.com/Developer/IS/en_US/7.4/operations.html#call_WorkflowQueue_V3_GET-workflowQueue-id
/// </summary>
/// <param name="WorkflowQueueID"></param>
/// <returns></returns>
public static async Task<WorkflowQueue> GetWorkflowQueue(string WorkflowQueueID)
{
    //Get the specific workflow queue data
    var retval = await GetRequest(BaseURL + $"workflowQueue/{WorkflowQueueID}");

    //Parse the JSON to object
    WorkflowQueue json = JsonConvert.DeserializeObject<WorkflowQueue>(retval);  //parse the JSON to object

    return json;
}