Skip to main content

.NET API - How to Obtain MultiCall Error Info

SteveD-1097
Original Poster

A question came-up recently from someone using the .NET API and looking to find the error details returned by a MultiCall - the requestIndex in particular.

Join the conversation

You need to be logged in to reply to this post and participate in the Geotab Community discussions.

Top Answers

SteveD-1097
Original Poster

The following example demonstrates how the error information returned by a MultiCall can be obtained using the .NET API in C# (note that the authentication logic is wrapped in another method for brevity):

// Authenticate MyGeotab API. myGeotabApi = await GeotabSdkUtility.AuthenticateMyGeotabApiAsync(GeotabServer, databaseName, userName, password);   var calls = new List<object>();   // Note: Use an invalid User Id in one of the following calls to trigger an exception in the MultiCall. calls.Add(new object[] { "Get", typeof(DutyStatusAvailability), new { search = new DutyStatusAvailabilitySearch { UserSearch = new UserSearch { Id = Id.Create("b126") } } }, typeof(List<DutyStatusAvailability>) }); calls.Add(new object[] { "Get", typeof(DutyStatusAvailability), new { search = new DutyStatusAvailabilitySearch { UserSearch = new UserSearch { Id = Id.Create("b16D") } } }, typeof(List<DutyStatusAvailability>) }); calls.Add(new object[] { "Get", typeof(DutyStatusAvailability), new { search = new DutyStatusAvailabilitySearch { UserSearch = new UserSearch { Id = Id.Create("bXXX") } } }, typeof(List<DutyStatusAvailability>) }); calls.Add(new object[] { "Get", typeof(DutyStatusAvailability), new { search = new DutyStatusAvailabilitySearch { UserSearch = new UserSearch { Id = Id.Create("b130") } } }, typeof(List<DutyStatusAvailability>) });   List<object> results; try { // Execute MultiCall. results = await myGeotabApi.MultiCallAsync(calls.ToArray()); } catch (Exception exception) { var exceptionData = exception.Data; var exceptionDataValues = exceptionData.Values; foreach (var item in exceptionDataValues) { if (item is JsonRpcErrorData) { var errorData = (JsonRpcErrorData)item; var errorId = errorData.Id; var errorInfo = errorData.Info; var errorRequestIndex = errorData.RequestIndex; var errorType = errorData.Type; // TODO: Add logic to utilize error info...   break; } } }

In this example, a number of calls are added to a list and executed in a MultiCall. One of the calls has an invalid User Id. When the MultiCall throws an exception, the JsonRpcErrorData is extracted from the exception, making it possible to know what went wrong and which of the calls triggered the exception. From there, appropriate handling logic can be added.

1 Reply

SteveD-1097
Original Poster

The following example demonstrates how the error information returned by a MultiCall can be obtained using the .NET API in C# (note that the authentication logic is wrapped in another method for brevity):

// Authenticate MyGeotab API. myGeotabApi = await GeotabSdkUtility.AuthenticateMyGeotabApiAsync(GeotabServer, databaseName, userName, password);   var calls = new List<object>();   // Note: Use an invalid User Id in one of the following calls to trigger an exception in the MultiCall. calls.Add(new object[] { "Get", typeof(DutyStatusAvailability), new { search = new DutyStatusAvailabilitySearch { UserSearch = new UserSearch { Id = Id.Create("b126") } } }, typeof(List<DutyStatusAvailability>) }); calls.Add(new object[] { "Get", typeof(DutyStatusAvailability), new { search = new DutyStatusAvailabilitySearch { UserSearch = new UserSearch { Id = Id.Create("b16D") } } }, typeof(List<DutyStatusAvailability>) }); calls.Add(new object[] { "Get", typeof(DutyStatusAvailability), new { search = new DutyStatusAvailabilitySearch { UserSearch = new UserSearch { Id = Id.Create("bXXX") } } }, typeof(List<DutyStatusAvailability>) }); calls.Add(new object[] { "Get", typeof(DutyStatusAvailability), new { search = new DutyStatusAvailabilitySearch { UserSearch = new UserSearch { Id = Id.Create("b130") } } }, typeof(List<DutyStatusAvailability>) });   List<object> results; try { // Execute MultiCall. results = await myGeotabApi.MultiCallAsync(calls.ToArray()); } catch (Exception exception) { var exceptionData = exception.Data; var exceptionDataValues = exceptionData.Values; foreach (var item in exceptionDataValues) { if (item is JsonRpcErrorData) { var errorData = (JsonRpcErrorData)item; var errorId = errorData.Id; var errorInfo = errorData.Info; var errorRequestIndex = errorData.RequestIndex; var errorType = errorData.Type; // TODO: Add logic to utilize error info...   break; } } }

In this example, a number of calls are added to a list and executed in a MultiCall. One of the calls has an invalid User Id. When the MultiCall throws an exception, the JsonRpcErrorData is extracted from the exception, making it possible to know what went wrong and which of the calls triggered the exception. From there, appropriate handling logic can be added.

Still have questions?