Perceptive Content Integration API - Session Management

This article demonstrates one way a custom application can start and end a session with the Integration Server API. The code example comes from an asynchronous .Net WebAPI written in C#.

Create a Session and Get an Access Token

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

public static async Task<string> GetSession()
{
    //Get basic auth credentials for Integration server account from secure location
    string username = ConfigurationManager.AppSettings["IntegrationUser"];
    string password = ConfigurationManager.AppSettings["IntegrationPassword"];

    //http client data persists so first we clear headers
    client.DefaultRequestHeaders.Clear();

    //add auth credentials to the Authorization header
    var byteArray = Encoding.ASCII.GetBytes(username + ":" + password);
    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

    //Send the GET request
    HttpResponseMessage response = await client.GetAsync(BaseURL + "connection");

    //throws exception if remote server does not return success code
    response.EnsureSuccessStatusCode();

    //Token is retrieved from the response headers and saved globally
    Token = response.Headers.GetValues("X-IntegrationServer-Session-Hash").FirstOrDefault();

    return Token;
}

End Session

public static async Task<string> CloseSession()
{
    //http client data persists so first we clear headers
    client.DefaultRequestHeaders.Clear();

    //Send the DELETE request
    HttpResponseMessage response = await client.DeleteAsync(BaseURL + "connection");

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

Example Usage

public async Task<Document> GetDocument(string DocID)
{
    //open the session 
    await PerceptiveActions.GetSession();

    //Token saved to variable in PerceptiveActions class and accessed from memory
    //in the GetDocument method
    Document json = await PerceptiveActions.GetDocument(DocID);

    //close the session
    await PerceptiveActions.CloseSession();  

    return json;
}


KeywordsPerceptive Content Integration API Session Management   Doc ID102520
OwnerNick W.GroupECMS
Created2020-05-26 11:03:39Updated2020-06-09 12:00:51
SitesECMS
CleanURLhttps://kb.wisc.edu/ecms/perceptive-content-integration-api
Feedback  0   0