Class API
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 class API : IApi
- Inheritance
-
API
- Implements
- Inherited Members
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.
Constructors
API(Credentials, ApiClientConfiguration?)
Initializes a new instance of the API class.
public API(Credentials credentials, ApiClientConfiguration? apiClientConfiguration = null)
Parameters
credentialsCredentialsThe Credentials.
apiClientConfigurationApiClientConfigurationThe ApiClientConfiguration provided by the API client for custom configurations.
API(string, string?, string?, string, string?, int, HttpMessageHandler?, ApiClientConfiguration?)
Initializes a new instance of the API class.
public API(string userName, string? password, string? sessionId, string database, string? server = null, int timeout = 300000, HttpMessageHandler? handler = null, ApiClientConfiguration? apiClientConfiguration = null)
Parameters
userNamestringThe user name to use for authentication.
passwordstringThe password to use for authentication. Note: password OR sessionId are required. Both can be supplied.
sessionIdstringThe session ID if user is already authenticated. Note: password OR sessionId are required. Both can be supplied. If only session ID is supplied the API cannot re-authenticate.
databasestringThe name of the database the user belongs to.
serverstringThe server federation name. Default: my.geotab.com. Note: this should NOT be a specific server (my3.geotab.com) databases can be moved to different servers to maximize performance without warning.
timeoutintThe timeout for the requests in milliseconds (Default 300000).
handlerHttpMessageHandlerThe HttpMessageHandler to be used with the HttpClient request. The HttpMessageHandler provides additional control over see cref="HttpClient"/> request. The API object will not dispose of this object.
apiClientConfigurationApiClientConfigurationThe ApiClientConfiguration provided by the API client for custom configurations.
API(string, string, string, string, string, IWebProxy, int)
Initializes a new instance of the API class.
[Obsolete("proxy has been deprecated and is ignored, if require use of proxy please use constructor with HttpMessageHandler provided", false)]
public API(string userName, string password, string sessionId, string database, string server, IWebProxy proxy, int timeout = 300000)
Parameters
userNamestringThe user name to use for authentication.
passwordstringThe password to use for authentication. Note: password OR sessionId are required. Both can be supplied.
sessionIdstringThe session ID if user is already authenticated. Note: password OR sessionId are required. Both can be supplied. If only session ID is supplied the API cannot re-authenticate.
databasestringThe name of the database the user belongs to.
serverstringThe server federation name. Default: my.geotab.com. Note: this should NOT be a specific server (my3.geotab.com) databases can be moved to different servers to maximize performance without warning.
proxyIWebProxyThe IWebProxy to use.
timeoutintThe timeout for the requests in milliseconds (Default 300000).
Properties
Database
Gets or sets the specific database on the server to which the API call is being made.
public string Database { get; set; }
Property Value
LoginResult
Gets or sets the result of the login request.
public LoginResult? LoginResult { get; set; }
Property Value
Password
Sets the user's password.
public string Password { set; }
Property Value
Proxy
Gets or sets IWebProxy to use in the request />.
[Obsolete("proxy has been deprecated and is ignored, if require use of proxy please use constructor with HttpMessageHandler provided", false)]
public IWebProxy? Proxy { get; set; }
Property Value
Server
Gets or sets the name of the server that the API call is being made to.
public 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.
public string? SessionId { get; set; }
Property Value
Timeout
Gets or sets the timeout for the requests in milliseconds.
public int Timeout { get; set; }
Property Value
UserName
Gets or sets the username (typically an email address) that identifies the user being authenticated.
public 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.")]
public void Authenticate()
Remarks
The method is marked as Obsolete.
AuthenticateAsync(CancellationToken)
Authenticate the user in an async call.
public Task AuthenticateAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe 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.
public Task<T?> CallAsync<T>(string method, object? parameters = null, CancellationToken cancellationToken = default)
Parameters
methodstringThe method name to call.
parametersobjectAn anonymous object containing properties (param name) with values (param value). Property name must match that of the method parameter.
cancellationTokenCancellationTokenThe CancellationToken used to single that the request should be canceled.
Returns
- Task<T>
The result for queries and null for non queries (Add, Set, Remove).
Type Parameters
TThe 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.
public Task<T?> CallAsync<T>(string method, Type type, object? parameters = null, CancellationToken cancellationToken = default)
Parameters
methodstringThe method name to call.
typeTypeThe Type use in the generic api call.
parametersobjectAn anonymous object containing properties (param name) with values (param value). Property name must match that of the method parameter.
cancellationTokenCancellationTokenThe CancellationToken used to single that the request should be canceled.
Returns
- Task<T>
The result for queries and null for non queries (Add, Set, Remove).
Type Parameters
TThe 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.")]
public T? Call<T>(string method, object? parameters = null)
Parameters
methodstringThe method name to call.
parametersobjectAn 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
TThe 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.")]
public T? Call<T>(string method, Type type, object? parameters = null)
Parameters
methodstringThe method name to call.
typeTypeThe Type use in the generic call.
parametersobjectAn 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
TThe return object type.
Remarks
The method is marked as Obsolete.
Clone()
Creates a new object that is a copy of the current instance.
public 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.
public Task DownloadAsync(Stream outputStream, MediaFile mediaFile, CancellationToken cancellationToken = default)
Parameters
outputStreamStreamThe Stream to write downloaded binary data to.
mediaFileMediaFileThe MediaFile corresponding to the file to download.
cancellationTokenCancellationTokenThe 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.")]
public List<object?> MultiCall(params object[] arguments)
Parameters
argumentsobject[]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.
public Task<List<object?>> MultiCallAsync(params object[] arguments)
Parameters
argumentsobject[]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.
public Task UploadAsync(Stream inputStream, MediaFile mediaFile, CancellationToken cancellationToken = default)
Parameters
inputStreamStreamThe Stream of binary data to upload.
mediaFileMediaFileThe fully populated MediaFile corresponding to the file to upload.
cancellationTokenCancellationTokenThe CancellationToken used to single that the request should be canceled.