Interface IApi
Used to make API calls against a MyGeotab web server. This object is typically used when using the API from a Microsoft .Net language, like C#, VB.Net or managed C++. It makes it easy to invoke the various methods and receive the results. It also automates of some tasks such as handling a database that was moved from one server to another or credentials expiring. This class is thread safe.
public interface IApi
Remarks
The maximum number of concurrent connections per server is 64, provided by the default HttpMessageHandler. It can be increased/decreased by providing a custom instance of HttpMessageHandler.
Properties
Database
Gets or sets the specific database on the server to which the API call is being made.
string Database { get; set; }
Property Value
LoginResult
Gets or sets the result of the login request.
LoginResult? LoginResult { get; set; }
Property Value
Password
Sets the user's password.
string Password { set; }
Property Value
Server
Gets or sets the name of the server that the API call is being made to.
string Server { get; set; }
Property Value
SessionId
Gets or sets the token generated from the authentication call which can be used to make the API call instead of the password.
string? SessionId { get; set; }
Property Value
Timeout
Gets or sets the timeout for the requests in milliseconds.
int Timeout { get; set; }
Property Value
UserName
Gets or sets the username (typically an email address) that identifies the user being authenticated.
string UserName { get; set; }
Property Value
Methods
Authenticate()
Authenticate the user. This method is deprecated. Rather use AuthenticateAsync(CancellationToken)
[Obsolete("Asynchronous AuthenticateAsync method is better for performance.")]
void Authenticate()
Remarks
The method is marked as Obsolete.
AuthenticateAsync(CancellationToken)
Authenticate the user in an async call.
Task AuthenticateAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe CancellationToken used to single that the request should be cancelled.
Returns
- Task
A Task which is a result of calling AuthenticateImplAsync.
CallAsync<T>(string, object?, CancellationToken)
Make an API request using a non-generic type method. This is an async call.
Task<T?> CallAsync<T>(string method, object? parameters = null, CancellationToken cancellationToken = default)
Parameters
method
stringThe method name to call.
parameters
objectAn anonymous object containing properties (param name) with values (param value). Property name must match that of the method parameter.
cancellationToken
CancellationTokenThe CancellationToken used to single that the request should be cancelled.
Returns
- Task<T>
The result for queries and null for non queries (Add, Set, Remove).
Type Parameters
T
The return object type.
CallAsync<T>(string, Type, object?, CancellationToken)
Make an API call using a generic type method. Generic type methods are methods that have the same name but take a specific object type. This is an async call.
Task<T?> CallAsync<T>(string method, Type type, object? parameters = null, CancellationToken cancellationToken = default)
Parameters
method
stringThe method name to call.
type
TypeThe Type use in the generic api call.
parameters
objectAn anonymous object containing properties (param name) with values (param value). Property name must match that of the method parameter.
cancellationToken
CancellationTokenThe CancellationToken used to single that the request should be cancelled.
Returns
- Task<T>
The result for queries and null for non queries (Add, Set, Remove).
Type Parameters
T
The return object type.
Call<T>(string, object?)
Make an API request using a non-generic type method.
[Obsolete("Asynchronous CallAsync method is better for performance.")]
T? Call<T>(string method, object? parameters = null)
Parameters
method
stringThe method name to call.
parameters
objectAn anonymous object containing properties (param name) with values (param value). Property name must match that of the method parameter.
Returns
- T
The result for queries and null for non queries (Add, Set, Remove).
Type Parameters
T
The return object type.
Call<T>(string, Type, object?)
Make an API call using a generic type method. Generic type methods are methods that have the same name but take a specific object type.
[Obsolete("Asynchronous CallAsync method is better for performance.")]
T? Call<T>(string method, Type type, object? parameters = null)
Parameters
method
stringThe method name to call.
type
TypeThe Type use in the generic call.
parameters
objectAn anonymous object containing properties (param name) with values (param value). Property name must match that of the method parameter.
Returns
- T
The result for queries and null for non queries (Add, Set, Remove).
Type Parameters
T
The return object type.
Remarks
The method is marked as Obsolete.
Clone()
Creates a new object that is a copy of the current instance.
object Clone()
Returns
- object
A new object that is a copy of this instance.
DownloadAsync(Stream, MediaFile, CancellationToken)
Make an API call using generic type method to Download a stream of data.
Task DownloadAsync(Stream outputStream, MediaFile mediaFile, CancellationToken cancellationToken = default)
Parameters
outputStream
StreamThe Stream to write downloaded binary data to.
mediaFile
MediaFileThe MediaFile corresponding to the file to download.
cancellationToken
CancellationTokenThe CancellationToken used to single that the request should be canceled.
Returns
MultiCall(params object[])
Make multiple calls (MultiCall) against the database using a single HTTP request. Each "call" must contain the return Type as the last index.
[Obsolete("Asynchronous MultiCallAsync method is better for performance.")]
List<object?> MultiCall(params object[] arguments)
Parameters
arguments
object[]A an array of object arrays contain call arguments and Type (if not otherwise specified).
Returns
MultiCallAsync(params object[])
Make multiple calls (MultiCall) against the database using a single HTTP request. Each "call" must contain the return Type as the last index. This is an async call.
Task<List<object?>> MultiCallAsync(params object[] arguments)
Parameters
arguments
object[]A an array of object arrays contain call arguments and Type (if not otherwise specified).
Returns
UploadAsync(Stream, MediaFile, CancellationToken)
Make an API call using generic type method to Upload a stream of data.
Task UploadAsync(Stream inputStream, MediaFile mediaFile, CancellationToken cancellationToken = default)
Parameters
inputStream
StreamThe Stream of binary data to upload.
mediaFile
MediaFileThe fully populated MediaFile corresponding to the file to upload.
cancellationToken
CancellationTokenThe CancellationToken used to single that the request should be canceled.