Skip to main content

.NET SDK

The Mobiscroll Connect .NET SDK provides a convenient way to integrate Mobiscroll Connect in .NET backend applications. It targets .NET 8 and runs on .NET Core, making it compatible with Linux, macOS, and Windows.

Setup

Install the package using NuGet:

dotnet add package Mobiscroll.Connect

Client Initialization

To use the SDK, initialize MobiscrollConnectClient with your client credentials.

Class: Mobiscroll.Connect.MobiscrollConnectClient

constructorMobiscrollConnectClient

Constructor arguments.

clientIdstring

Your Client ID obtained from the Mobiscroll Connect dashboard.

clientSecretstring

Your Client Secret obtained from the Mobiscroll Connect dashboard.

redirectUristring

Your application's redirect URI that matches the one configured in the Mobiscroll Connect dashboard.

Usage:

using Mobiscroll.Connect;

var client = new MobiscrollConnectClient(
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET",
redirectUri: "YOUR_REDIRECT_URI"
);

Methods

SetCredentials

Sets the access token for the client. This is required before making any API calls that require authentication.

Method: client.Auth.SetCredentials(tokens)

tokensTokenResponse

The token response object returned by client.Auth.GetTokenAsync(code).

OnTokensRefreshed

Registers a callback to be invoked whenever the SDK automatically refreshes the access token. Use this to persist the updated tokens so they survive future requests.

Method: client.OnTokensRefreshed(callback)

callbackAction<TokenResponse>

An action that receives the updated TokenResponse after a successful automatic token refresh.

Token Refresh

The .NET SDK handles token refresh automatically. When any API call returns a 401 Unauthorized response and the client has a refresh_token stored, the SDK will silently exchange it for a new access token and retry the original request — with no action required from your application.

When the refresh succeeds, the SDK invokes your OnTokensRefreshed callback with the updated TokenResponse. You must register this callback and persist the new tokens, otherwise they will be lost between requests.

client.OnTokensRefreshed(updatedTokens =>
{
// Persist updatedTokens in your database or session store
// so the new access_token and refresh_token survive future requests
HttpContext.Session.SetString("access_token", updatedTokens.AccessToken);
HttpContext.Session.SetString("refresh_token", updatedTokens.RefreshToken ?? "");
});

If the refresh token itself is invalid or has been revoked, the SDK throws an AuthenticationException and the user must re-authorize.

Error Handling

All SDK methods throw exceptions that extend Mobiscroll.Connect.Exceptions.MobiscrollConnectException. You can catch the base exception or any of the specific subclasses.

ExceptionHTTP StatusErrorCode
AuthenticationException401, 403AUTHENTICATION_ERROR
ValidationException400, 422VALIDATION_ERROR
NotFoundException404NOT_FOUND_ERROR
RateLimitException429RATE_LIMIT_ERROR
ServerException5xxSERVER_ERROR
NetworkExceptionNETWORK_ERROR

ValidationException exposes a Details property with field-level validation errors. RateLimitException exposes RetryAfter (seconds) and ServerException exposes StatusCode.

using Mobiscroll.Connect.Exceptions;

try
{
var response = await client.Events.ListAsync(new EventListParams
{
Start = DateTime.UtcNow,
End = DateTime.UtcNow.AddMonths(1)
});
}
catch (AuthenticationException)
{
// Token expired and refresh failed — re-authorize the user
}
catch (ValidationException ex)
{
// Invalid request parameters
var details = ex.Details;
}
catch (RateLimitException ex)
{
var retryAfter = ex.RetryAfter; // seconds
}
catch (MobiscrollConnectException)
{
// Catch-all for any other SDK error
}

API

The client exposes resources that map directly to the API endpoints.

Auth

The client.Auth resource handles the OAuth authorization flow, including generating authorization URLs, exchanging codes for tokens, managing connection status, and disconnecting providers.

To localize the Connect pages, pass an optional Lng (en, es, fr, ar) to GenerateAuthUrl, e.g. new AuthorizeParams { UserId = ..., Lng = "es" }. When omitted, the UI falls back to the browser's Accept-Language header, then English; Arabic renders right-to-left.

Calendars

The client.Calendars resource allows you to list available calendars from all connected providers (Google, Outlook, etc.). It corresponds to the /calendars endpoints.

Events

The client.Events resource provides methods to create, read, update, and delete calendar events across all connected accounts. It corresponds to the /events endpoints.