Class MerakiClient
A Meraki Dashboard API client. This is your starting point for all API operations. Example usage:
using Meraki.Api;
using System;
using System.Threading.Tasks;
namespace My.Project;
public static class Program
{
public static async Task Main()
{
using var merakiClient = new MerakiClient(
new MerakiClientOptions
{
ApiKey = "0123456789abcdef0123456789abcdef01234567",
UserAgent = "YourProductName/YourProductVersion YourCompanyName"
}
);
var organizations = await merakiClient
.Organizations
.GetOrganizationsAsync()
.ConfigureAwait(false);
var firstOrganization = organizations[0];
var devices = await merakiClient
.Organizations
.Devices
.GetOrganizationDevicesAsync(firstOrganization.Id)
.ConfigureAwait(false);
Console.WriteLine("Devices:");
foreach (var device in devices)
{
Console.WriteLine($" - {device.Serial}: {device.Name}");
}
}
}
public class MerakiClient : IDisposable
- Inheritance
-
MerakiClient
- Implements
- Inherited Members
Remarks
This routes through the same core HttpClient as every typed endpoint, so it inherits authentication, read-only gating, rate limiting and 429/5xx back-off from the internal authenticated handler automatically. It exists so callers that need endpoints not (yet) surfaced as typed methods - or that must choose the endpoint at runtime - can still benefit from the client's transport behaviour.
Constructors
MerakiClient(MerakiClientOptions, ILogger?)
A Meraki portal client
public MerakiClient(MerakiClientOptions options, ILogger? logger = null)
Parameters
optionsMerakiClientOptionsloggerILogger
Properties
ApiClientVersion
Gets the api client version
public string ApiClientVersion { get; }
Property Value
Appliance
Gets the appliance
public ApplianceSection Appliance { get; }
Property Value
Camera
Generate a snapshot of what the camera sees at the specified time and return a link to that image.
public CameraSection Camera { get; }
Property Value
CellularGateway
Gets the cellular gateway
public CellularGatewaySection CellularGateway { get; }
Property Value
Devices
Return a single device
public DevicesSection Devices { get; }
Property Value
Insight
Gets the insight
public InsightSection Insight { get; }
Property Value
IsReadOnly
Used to find out whether the client has the ReadOnly option set
public bool IsReadOnly { get; }
Property Value
LastRequestUri
Gets the URI of the last API request made by this client
public string LastRequestUri { get; }
Property Value
LastResponseHeaders
Gets the last response headers
public HttpResponseHeaders? LastResponseHeaders { get; set; }
Property Value
Licensing
Gets the licensing
public LicensingSection Licensing { get; }
Property Value
LiveTools
Gets the live tools
public LiveToolsSection LiveTools { get; }
Property Value
Networks
Return a network
public NetworksSection Networks { get; }
Property Value
Organizations
List the organizations that the user has privileges on
public OrganizationsSection Organizations { get; }
Property Value
SecureConnect
Gets the secure connect
public SecureConnectSection SecureConnect { get; }
Property Value
Sensor
Gets the sensor
public SensorSection Sensor { get; }
Property Value
SensorRanges
Gets sensor reading ranges and thresholds for various sensor metrics, consistent with the Meraki Dashboard UI
public static Dictionary<SensorMetrics, List<SensorRange>> SensorRanges { get; }
Property Value
Sm
Gets the sm
public SmSection Sm { get; }
Property Value
Statistics
Gets statistics about API requests made by this client
public MerakiClientStatistics Statistics { get; }
Property Value
Switch
Gets the switch
public SwitchSection Switch { get; }
Property Value
Wireless
Gets the wireless
public WirelessSection Wireless { get; }
Property Value
Methods
Dispose()
Dispose
public void Dispose()
Dispose(bool)
Releases the unmanaged resources used by the MerakiClient and optionally releases the managed resources
protected virtual void Dispose(bool disposing)
Parameters
disposingbooltrue to release both managed and unmanaged resources; false to release only unmanaged resources
GetAllAsync<T>(Func<int, string?, string?, CancellationToken, Task<List<T>>>, int, CancellationToken)
Retrieves all items using pagination with a per-page count parameter
public Task<List<T>> GetAllAsync<T>(Func<int, string?, string?, CancellationToken, Task<List<T>>> pageFactoryAsync, int perPage, CancellationToken cancellationToken)
Parameters
pageFactoryAsyncFunc<int, string, string, CancellationToken, Task<List<T>>>The function to call for each page of results
perPageintThe number of items per page
cancellationTokenCancellationTokenThe cancellation token
Returns
Type Parameters
TThe type of items to retrieve
GetAllAsync<T>(Func<int?, string?, string?, CancellationToken, Task<ApiResponse<List<T>>>>, int, CancellationToken)
Retrieves all items using pagination with per-page count and ApiResponse wrapper
public static Task<List<T>> GetAllAsync<T>(Func<int?, string?, string?, CancellationToken, Task<ApiResponse<List<T>>>> pageFactoryAsync, int perPage, CancellationToken cancellationToken)
Parameters
pageFactoryAsyncFunc<int?, string, string, CancellationToken, Task<ApiResponse<List<T>>>>The function to call for each page of results
perPageintThe number of items per page
cancellationTokenCancellationTokenThe cancellation token
Returns
Type Parameters
TThe type of items to retrieve
GetAllAsync<T>(Func<string?, string?, string?, string?, double?, CancellationToken, Task<ApiResponse<List<T>>>>, string?, string?, double?, CancellationToken)
Retrieves all items using pagination with time-based parameters
public static Task<List<T>> GetAllAsync<T>(Func<string?, string?, string?, string?, double?, CancellationToken, Task<ApiResponse<List<T>>>> pageFactoryAsync, string? t0 = null, string? t1 = null, double? timeSpan = null, CancellationToken cancellationToken = default)
Parameters
pageFactoryAsyncFunc<string, string, string, string, double?, CancellationToken, Task<ApiResponse<List<T>>>>The function to call for each page of results
t0stringThe beginning of the timespan
t1stringThe end of the timespan
timeSpandouble?The timespan duration
cancellationTokenCancellationTokenThe cancellation token
Returns
Type Parameters
TThe type of items to retrieve
GetAllAsync<T>(Func<string?, string?, CancellationToken, Task<ApiResponse<List<T>>>>, CancellationToken)
Retrieves all items using pagination with ApiResponse wrapper
public static Task<List<T>> GetAllAsync<T>(Func<string?, string?, CancellationToken, Task<ApiResponse<List<T>>>> pageFactoryAsync, CancellationToken cancellationToken)
Parameters
pageFactoryAsyncFunc<string, string, CancellationToken, Task<ApiResponse<List<T>>>>The function to call for each page of results
cancellationTokenCancellationTokenThe cancellation token
Returns
Type Parameters
TThe type of items to retrieve
GetAllAsync<T>(Func<string?, string?, CancellationToken, Task<List<T>>>, CancellationToken)
Retrieves all items using pagination with startingAfter/endingBefore parameters
public Task<List<T>> GetAllAsync<T>(Func<string?, string?, CancellationToken, Task<List<T>>> pageFactoryAsync, CancellationToken cancellationToken)
Parameters
pageFactoryAsyncFunc<string, string, CancellationToken, Task<List<T>>>The function to call for each page of results
cancellationTokenCancellationTokenThe cancellation token
Returns
Type Parameters
TThe type of items to retrieve
GetAllFromResponsePropertyAsync<TResponse, TModel>(Func<string?, string?, CancellationToken, Task<ApiResponse<TResponse>>>, Func<ApiResponse<TResponse>, List<TModel>>, CancellationToken)
Retrieves all items from a paginated API response where the data is accessed via a custom accessor function.
public static Task<List<TModel>> GetAllFromResponsePropertyAsync<TResponse, TModel>(Func<string?, string?, CancellationToken, Task<ApiResponse<TResponse>>> pageFactoryAsync, Func<ApiResponse<TResponse>, List<TModel>> propertyFunction, CancellationToken cancellationToken)
Parameters
pageFactoryAsyncFunc<string, string, CancellationToken, Task<ApiResponse<TResponse>>>A function that asynchronously retrieves a page of data, given pagination parameters and a cancellation token.
propertyFunctionFunc<ApiResponse<TResponse>, List<TModel>>A function that extracts a list of models from the API response.
cancellationTokenCancellationTokenA cancellation token to observe while waiting for the task to complete.
Returns
- Task<List<TModel>>
A task that represents the asynchronous operation. The task result contains a list of all models retrieved from all pages.
Type Parameters
TResponseThe type of the API response object.
TModelThe type of the model to return in the list.
GetEndOfLifeDetailsAsync(CancellationToken)
Returns a list of end-of-life data. Data regularly updated from https://documentation.meraki.com/General_Administration/Other_Topics/Meraki_End-of-Life_(EOL)_Products_and_Dates
public static Task<List<DeviceModelEndOfLifeDetail>> GetEndOfLifeDetailsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
Exceptions
- ApiException
Thrown when fails to make API call
GetInfoFromSerialNumber(string)
Returns a list of end-of-life data Data regularly updated from https://documentation.meraki.com/General_Administration/Other_Topics/Meraki_End-of-Life_(EOL)_Products_and_Dates
public static SerialNumberInfo GetInfoFromSerialNumber(string serialNumber)
Parameters
serialNumberstring
Returns
QueryAsync(HttpMethod, string, string?, string?, bool, CancellationToken)
Executes an arbitrary Meraki Dashboard API v1 request.
public Task<MerakiQueryResponse> QueryAsync(HttpMethod method, string path, string? body = null, string? contentType = "application/json", bool followPagination = true, CancellationToken cancellationToken = default)
Parameters
methodHttpMethodThe HTTP method. Non-GET methods throw if the client is read-only.
pathstringThe path AFTER
/api/v1/(e.g.organizationsororganizations/{orgId}/appliance/uplink/statuses), optionally including a query string. A leading slash is ignored.bodystringThe raw request body to send, or null for none.
contentTypestringThe Content-Type for the body. Defaults to application/json.
followPaginationboolWhen true (default), GET requests that return a JSON array and a
Link: rel=nextheader are followed to completion and all pages are concatenated. Ignored for non-GET requests and non-array responses.cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<MerakiQueryResponse>
A MerakiQueryResponse describing the (final) response and its parsed JSON.
SetReadOnly(bool)
Used to change the Options Readonly state after client is created
public void SetReadOnly(bool readOnly)
Parameters
readOnlybool