OneSpan Sign How To: Using AuditService

Michael Williams,

I was asked a question about using the AuditService functionality of the API/SDK, recently, so I thought it would be a good idea to create a feature blog for it. In this blog, I will show how to use the getAudit() method to get the audit information for a completed package using both the .NET and Java SDKs. With that said, let us go ahead and jump right in.

The Code

.NET SDK

The code for this is quite simple. You can go ahead and copy and paste this code into your C# code file. I will describe the code, in more detail, below.

OneSpan Developer Community

OneSpan Developer Community

Join the OneSpan Developer Community! Forums, blogs, documentation, SDK downloads, and more.

Join Today
using System;
using Silanis.ESL.SDK;
using System.Diagnostics;
using System.Collections.Generic;

namespace GetAudit
{
    class GetAudit
    {
        private static String apiUrl = "https://sandbox.esignlive.com/api";
        private static String apiKey = "YOUR_API_KEY";

        public static void Main(string[] args)
        {
            EslClient eslClient = new EslClient(apiKey, apiUrl);
            PackageId packageId = new PackageId("COMPLETED_PACKAGE_ID");
            List<Audit> myaudit = eslClient.AuditService.GetAudit(packageId);
            List<Audit>.Enumerator myenum = myaudit.GetEnumerator();
            while(myenum.MoveNext())
            {
                Debug.WriteLine("DateTime - " + myenum.Current.dateTime + ", Type - " + myenum.Current.type + ", User - " + myenum.Current.user + ", Email - " + myenum.Current.email + ", IP - " + myenum.Current.ip + ", Target - " + myenum.Current.target + ", Data - " + myenum.Current.data);
            }
        }
        
    }
}

First, create your EslClient using the apiUrl (use apps instead of sandbox if using production instance) and apiKey (be sure to replace the marker with your key).

private static String apiUrl = "https://sandbox.esignlive.com/api";
private static String apiKey = "YOUR_API_KEY";

EslClient eslClient = new EslClient(apiKey, apiUrl);

You will also need a completed package’s ID. Normally you would dynamically grab this package ID from somewhere, but in this example, a static package ID is used. Simply replace the marker with a package ID of a completed package in your account.

PackageId packageId = new PackageId("COMPLETED_PACKAGE_ID");

The next two lines grab the list of Audit objects from the AuditService and create the enumerator used to step through the list.

List<Audit> myaudit = eslClient.AuditService.GetAudit(packageId);
List<Audit>.Enumerator myenum = myaudit.GetEnumerator();

Finally, you can use a while loop to walk through the list of Audit info. In this example, you write the different properties available out to the debug window.

while(myenum.MoveNext())
{
      Debug.WriteLine("DateTime - " + myenum.Current.dateTime + ", Type - " + myenum.Current.type + ", User - " + myenum.Current.user + ", Email - " + myenum.Current.email + ", IP - " + myenum.Current.ip + ", Target - " + myenum.Current.target + ", Data - " + myenum.Current.data);
}

You can see what this will look like after running the code, below the Java SDK section.

Java SDK

This is all very similar in Java. Below you will find the complete code that you can copy and paste into your Java class, followed by a more detailed overview of what each part does.

package com.esignlive.example;

import java.util.Iterator;
import java.util.List;
import com.silanis.esl.sdk.Audit;
import com.silanis.esl.sdk.EslClient;
import com.silanis.esl.sdk.PackageId;

public class GetAudit {
	public static final String API_KEY = "YOUR_API_KEY";
	public static final String API_URL = "https://sandbox.esignlive.com/api";
  
	public static void main( String[] args ){
		EslClient eslClient = new EslClient( API_KEY, API_URL );
		PackageId packageId = new PackageId("COMPLETED_PACKAGE_ID");

		List<Audit> auditList = eslClient.getAuditService().getAudit(packageId);
		Iterator<Audit> iter = auditList.iterator();
		while(iter.hasNext())
		{
			Audit myaudit = iter.next();
			System.out.println("DateTime - " + myaudit.getDateTime() + ", Type - " + myaudit.getType() + ", User - " + myaudit.getUser() + ", Email - " + myaudit.getEmail() + ", IP - " + myaudit.getIp() + ", Target - " + myaudit.getTarget() + ", Data - " + myaudit.getData());
		}
	}
}

Just like in the .NET example above, the first thing you will do is create your EslClient with your API_KEY and API_URL (remember to use apps instead of sandbox for production).

public static final String API_KEY = "YOUR_API_KEY";
public static final String API_URL = "https://sandbox.esignlive.com/api";

EslClient eslClient = new EslClient( API_KEY, API_URL );

Next, you will create a new PackageId object using a static packageId string. As stated in the .NET example, you will normally get this dynamically from somewhere, but this example uses a static value for simplicity.

PackageId packageId = new PackageId("COMPLETED_PACKAGE_ID");

Now, you will grab the list of Audit information and create your list iterator.

List<Audit> auditList = eslClient.getAuditService().getAudit(packageId);
Iterator<Audit> iter = auditList.iterator();

Finally, you can use a while loop to step through the list of Audit information. With each loop, the different property values are printed to the console.

while(iter.hasNext())
{
	Audit myaudit = iter.next();
	System.out.println("DateTime - " + myaudit.getDateTime() + ", Type - " + myaudit.getType() + ", User - " + myaudit.getUser() + ", Email - " + myaudit.getEmail() + ", IP - " + myaudit.getIp() + ", Target - " + myaudit.getTarget() + ", Data - " + myaudit.getData());
}

The Output

When you execute this code, you will see each step of the audit trail for this package, as seen below. This is the .NET output, but the Java output will be essentially the same.

cSharpGetAuditOutput

Thanks for reading! If you have any questions or there are any topics you would like to see covered in my blog, feel free to post in the comments section.

– Michael Williams
Twitter | Facebook | LinkedIn