kbessette | Posts: 4

GetUpdatedPackagesWithinDateRange Unhandled Exception

0 votes
I'm having some difficulty implementing DownloadDocumentsDateRange posted previously in this forum. When the following code is executed the EslClient.PackageService.GetUpdatedPackagesWithinDateRange function throws an unhandled exception stating that an unexpected character was encountered while parsing value. I assume the string it's trying to parse is the response from eSignLive but I'm at a loss on how to debug it. Is there a way to capture and view this response? Is there documentation on the EslClient class that could shed light on what value the GetUpdatedPackagesWithinDateRange is expecting?
using System;
using System.IO;
using System.Threading;
using Silanis.ESL.SDK;
using System.Diagnostics;
using Silanis.ESL.SDK.Builder;



namespace DownloadDocumentsDateRange
{
    class DownloadDocuments
    {
        public static void Main(string[] args)
        {
            //API Identification Strings
            String apiUrl = "https://sandbox.esignlive.com/api";
            String apiKey = "***Redacted***";

            //Proxy info
            string httpProxyURL = "***Redacted***";
            int httpProxyPort = ***Redacted***;
            
            //Build Proxy Configuration
            ProxyConfiguration httpProxyConfiguration = ProxyConfigurationBuilder.NewProxyConfiguration()
            .WithHttpHost(httpProxyURL)
            .WithHttpPort(httpProxyPort)
            .Build();

            //Set EslClient
            EslClient eslClient = new EslClient(apiKey, apiUrl, httpProxyConfiguration);

            //starting point to retrieve completed packages
            int index = 1;

            //Retrieve first 50 completed packages. Packages are returned as a page from eSignLive.
            Page completedPackages = eslClient.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.COMPLETED, new PageRequest(index, 50), DateTime.Today.AddDays(-30), DateTime.Now);

            while (index = completedPackages.TotalElements)
            {
                foreach (DocumentPackage package in completedPackages)
                {
                    //for each completed package, get the package id to download signed documents.
                    Debug.WriteLine("Downloading package: " + package.Id + "...");
                    byte[] zipContent = eslClient.DownloadZippedDocuments(package.Id);
                    File.WriteAllBytes("C:\\" + package.Id.ToString() + ".zip", zipContent);
                    index++;
                    Thread.Sleep(1000);
                }
                //Retrieve next 50 packages
                completedPackages = eslClient.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.COMPLETED, new PageRequest(index, 50), DateTime.Today.AddDays(-30), DateTime.Now);
            }
            Debug.WriteLine("Downloaded All File!");
        }
    }
}
Here's the full stack trace.
Silanis.ESL.SDK.EslException was unhandled
  HResult=-2146233088
  Message=Could not get package list. Exception: Unexpected character encountered while parsing value: . Path '', line 0, position 0.
  Source=Silanis.ESL
  StackTrace:
       at Silanis.ESL.SDK.Services.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus status, PageRequest request, DateTime from, DateTime to)
       at DownloadDocumentsDateRange.DownloadDocuments.Main(String[] args) in ***Redacted***:line 39
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146233088
       LineNumber=0
       LinePosition=0
       Message=Unexpected character encountered while parsing value: . Path '', line 0, position 0.
       Path=""
       Source=Newtonsoft.Json
       StackTrace:
            at Newtonsoft.Json.JsonTextReader.ParseValue()
            at Newtonsoft.Json.JsonTextReader.ReadInternal()
            at Newtonsoft.Json.JsonTextReader.Read()
            at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
            at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
            at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
            at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
            at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
            at Silanis.ESL.SDK.EslServerException..ctor(String message, String errorDetails, WebException cause)
            at Silanis.ESL.SDK.Internal.HttpMethods.GetHttpJson(String apiToken, String path, String acceptType)
            at Silanis.ESL.SDK.RestClient.Get(String path)
            at Silanis.ESL.SDK.Services.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus status, PageRequest request, DateTime from, DateTime to)
       InnerException: 
Thanks for taking a look!

Approved Answer
harishaidary | Posts: 1812

Reply to: GetUpdatedPackagesWithinDateRange Unhandled Exception

0 votes
Are you able to do any other calls? Could you try a simple GetApplicationVersion() without the use of a proxy:
eslClient.SystemService.GetApplicationVersion();

harishaidary | Posts: 1812

Reply to: GetUpdatedPackagesWithinDateRange Unhandled Exception

0 votes
Hi there, Did you try getting the updated packages without the use of a proxy?

kbessette | Posts: 4

Reply to: GetUpdatedPackagesWithinDateRange Unhandled Exception

0 votes
Hi Haris, Thanks for the suggestion! I've commented out the proxy info and removed httpProxyConfiguration from the instantiation of eslClient. Now I'm getting a new exception from the same line of code, see below. Attached is the stdout.
using System;
using System.IO;
using System.Threading;
using Silanis.ESL.SDK;
using System.Diagnostics;

namespace DownloadDocumentsDateRange
{
    class DownloadDocuments
    {
        public static void Main(string[] args)
        {
            //API Identification Strings
            String apiUrl = "https://sandbox.esignlive.com/api";
            String apiKey = "***Redacted***";

             /*
             //Proxy info
             string httpProxyURL = "";
             int httpProxyPort = ;

             //Build Proxy Configuration
             ProxyConfiguration httpProxyConfiguration = ProxyConfigurationBuilder.NewProxyConfiguration()
             .WithHttpHost(httpProxyURL)
             .WithHttpPort(httpProxyPort)
             .Build();

             //Create EslClient
             EslClient eslClient = new EslClient(apiKey, apiUrl, httpProxyConfiguration);
             */

            EslClient eslClient = new EslClient(apiKey, apiUrl);

            //starting point to retrieve completed packages
            int index = 1;

            //Retrieve first 50 completed packages. Packages are returned as a page from eSignLive.
            Page completedPackages = eslClient.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.COMPLETED, new PageRequest(index, 50), DateTime.Today.AddDays(-30), DateTime.Now);
            
            while (index = completedPackages.TotalElements)
            {
                foreach (DocumentPackage package in completedPackages)
                {
                    //for each completed package, get the package id to download signed documents.
                    Debug.WriteLine("Downloading package: " + package.Id + "...");
                    byte[] zipContent = eslClient.DownloadZippedDocuments(package.Id);
                    File.WriteAllBytes("C:\\package-documents-" + package.Id.ToString() + ".zip", zipContent);
                    index++;
                    Thread.Sleep(1000);
                }
                //Retrieve next 50 packages
                completedPackages = eslClient.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.COMPLETED, new PageRequest(index, 50), DateTime.Today.AddDays(-30), DateTime.Now);
            }
            Debug.WriteLine("Downloaded All File!");
        }
    }
}
Here's the new exception.
Silanis.ESL.SDK.EslException was unhandled
  HResult=-2146233088
  Message=Could not get package list. Exception: Object reference not set to an instance of an object.
  Source=Silanis.ESL
  StackTrace:
       at Silanis.ESL.SDK.Services.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus status, PageRequest request, DateTime from, DateTime to)
       at DownloadDocumentsDateRange.DownloadDocuments.Main(String[] args) in ***Redacted***:line 38
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2147467261
       Message=Object reference not set to an instance of an object.
       Source=Silanis.ESL
       StackTrace:
            at Silanis.ESL.SDK.Internal.HttpMethods.GetHttpJson(String apiToken, String path, String acceptType)
            at Silanis.ESL.SDK.RestClient.Get(String path)
            at Silanis.ESL.SDK.Services.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus status, PageRequest request, DateTime from, DateTime to)
       InnerException: 
Thanks, Keith

Attachments
kbessette | Posts: 4

Reply to: GetUpdatedPackagesWithinDateRange Unhandled Exception

0 votes
No, it appears I can't make any other calls without the proxy. Same "Object reference not set to an instance of an object" exception. Adding the proxy info back in yields the "Unexpected character encountered while parsing value" error again. It's starting to appear that our security is preventing the call from leaving our network. I'll work in that direction. I'll update this thread with what I find. Thanks for the help!

harishaidary | Posts: 1812

Reply to: GetUpdatedPackagesWithinDateRange Unhandled Exception

0 votes
Sounds good. Let me know.

kbessette | Posts: 4

Reply to: GetUpdatedPackagesWithinDateRange Unhandled Exception

0 votes
Sure enough, it was security related. I needed to add authentication for the proxy. Thanks again!

harishaidary | Posts: 1812

Reply to: GetUpdatedPackagesWithinDateRange Unhandled Exception

0 votes
Glad you were able to resolve it :)

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off