.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:
- .NET CLI
- NuGet Package Manager
- PackageReference
dotnet add package Mobiscroll.Connect
NuGet\Install-Package Mobiscroll.Connect
<PackageReference Include="Mobiscroll.Connect" Version="*" />
Client Initialization
To use the SDK, initialize MobiscrollConnectClient with your client credentials.
Class: Mobiscroll.Connect.MobiscrollConnectClient
Constructor arguments.
Your Client ID obtained from the Mobiscroll Connect dashboard.
Your Client Secret obtained from the Mobiscroll Connect dashboard.
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)
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)
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.
| Exception | HTTP Status | ErrorCode |
|---|---|---|
AuthenticationException | 401, 403 | AUTHENTICATION_ERROR |
CalendarPermissionException | 403 | CALENDAR_PERMISSION_REQUIRED |
ValidationException | 400, 422 | VALIDATION_ERROR |
NotFoundException | 404 | NOT_FOUND_ERROR |
RateLimitException | 429 | RATE_LIMIT_ERROR |
ServerException | 5xx | SERVER_ERROR |
NetworkException | — | NETWORK_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
}
Auth API
The examples below assume using Mobiscroll.Connect; (the client and the Provider enum) and using Mobiscroll.Connect.Models; (the parameter and response classes).
The client.Auth resource handles the OAuth authorization flow, including generating authorization URLs, exchanging codes for tokens, managing connection status, and disconnecting providers.
Each account returned by GetConnectionStatusAsync reports GrantedScopes and CalendarPermissionGranted. A false flag means the account connected but withheld calendar access on the provider's consent screen, so it can list no calendars until the user reconnects — see Partial consent. Each account also reports syncState: reauth_required means the provider has since rejected the stored credentials and the account has stopped syncing — a different question from calendarPermissionGranted, which only records what was agreed at connect time. See Connection health.
When no connected account has calendar access, calendar and event calls raise CalendarPermissionException — Accounts names the accounts that must reconnect. It subclasses AuthenticationException, so existing handlers keep working.
To localize the Connect pages, pass an optional Lng 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, Hebrew and Persian render right-to-left. See Supported languages for the languages Connect supports.
🔐 OAuth API Reference
Auth.GenerateAuthUrl
Builds the URL that starts the authorization flow. Redirect the user to it: once they connect their calendars, Connect redirects them back to your redirect URI with an authorization code. The URL is built locally, without an API request. See GET /authorize.
Method: client.Auth.GenerateAuthUrl(AuthorizeParams authParams)
Returns: string
UserId is required: your identifier for the user. Scope, State and Lng are optional.
Usage:
// Generate the authorization URL
var authUrl = client.Auth.GenerateAuthUrl(new AuthorizeParams
{
UserId = "user-456",
// Optional parameters:
// Scope = "read-write",
// State = "xyz789",
// Lng = "es", // localize the Connect pages
});
// Redirect the user to authUrl
// return Redirect(authUrl);
Auth.GetTokenAsync
Exchanges the authorization code from your redirect URI for an access token and a refresh token. The client stores the returned tokens and uses them for the calls that follow. See POST /token.
Method: client.Auth.GetTokenAsync(string code, CancellationToken ct = default)
Returns: Task<TokenResponse>
The authorization code received on your redirect URI.
Usage:
// Exchange authorization code for access token
// The client is automatically authenticated with the new token
var tokenResponse = await client.Auth.GetTokenAsync(code);
// Persist tokenResponse to restore it later with client.Auth.SetCredentials()
Calendars API
The client.Calendars resource allows you to list available calendars from all connected providers (Google, Outlook, etc.). It corresponds to the /calendars endpoints.
📅 Calendars API Reference
Calendars.ListAsync
Lists the calendars of every account the user has connected. See GET /calendars.
Method: client.Calendars.ListAsync(CancellationToken ct = default)
Returns: Task<IReadOnlyList<Calendar>>
Usage:
var calendars = await client.Calendars.ListAsync();
Events API
The client.Events resource provides methods to create, read, update, and delete calendar events across all connected accounts. It corresponds to the /events endpoints.
📅 Events API Reference
Events.ListAsync
Lists events from the user's calendars, one page at a time. When the response contains a NextPageToken, pass it to the next call to get the following page. See GET /events.
Method: client.Events.ListAsync(EventListParams? listParams = null, CancellationToken ct = default)
Returns: Task<EventsListResponse>
All properties are optional: Start, End, CalendarIds (calendar IDs grouped by provider), PageSize, NextPageToken and SingleEvents.
Usage:
// Fetch initial events with date range filter
var response = await client.Events.ListAsync(new EventListParams
{
PageSize = 50,
Start = new DateTime(2025, 10, 1, 0, 0, 0, DateTimeKind.Utc),
End = new DateTime(2025, 10, 31, 23, 59, 59, DateTimeKind.Utc),
});
// Load more events using NextPageToken
var nextResponse = await client.Events.ListAsync(new EventListParams
{
PageSize = 50,
NextPageToken = response.NextPageToken,
});
// Filter by specific calendars
var filteredEvents = await client.Events.ListAsync(new EventListParams
{
PageSize = 25,
CalendarIds = new Dictionary<string, List<string>>
{
{ "google", new List<string> { "personal@gmail.com", "work@company.com" } }
},
});
// Get recurring event series masters (not expanded)
var masters = await client.Events.ListAsync(new EventListParams
{
PageSize = 50,
SingleEvents = false,
});
Events.CreateAsync
Creates an event in the given calendar. Set Recurrence to create a recurring series. See POST /event.
Method: client.Events.CreateAsync(EventCreateData data, CancellationToken ct = default)
Returns: Task<CalendarEvent>
Provider, CalendarId, Title, Start and End are required. Optional properties include Description, Location, AllDay and Recurrence. Pass Start and End as UTC values (DateTimeKind.Utc).
Usage:
// Create a simple event
var newEvent = await client.Events.CreateAsync(new EventCreateData
{
Provider = Provider.Google,
CalendarId = "primary",
Title = "Team Meeting",
Description = "Discuss project updates",
Start = new DateTime(2025, 11, 1, 10, 0, 0, DateTimeKind.Utc),
End = new DateTime(2025, 11, 1, 11, 0, 0, DateTimeKind.Utc),
Location = "Conference Room A",
});
// Create a recurring event
var recurringEvent = await client.Events.CreateAsync(new EventCreateData
{
Provider = Provider.Microsoft,
CalendarId = "AAMkAGVmMDEz...",
Title = "Weekly Standup",
Start = new DateTime(2025, 11, 1, 9, 0, 0, DateTimeKind.Utc),
End = new DateTime(2025, 11, 1, 9, 30, 0, DateTimeKind.Utc),
AllDay = false,
Recurrence = new RecurrenceRule
{
Frequency = "WEEKLY",
Interval = 1,
Count = 10,
ByDay = new List<string> { "MO", "WE", "FR" },
},
});
// Create an all-day event
var allDayEvent = await client.Events.CreateAsync(new EventCreateData
{
Provider = Provider.Apple,
CalendarId = "https://caldav.icloud.com/.../calendars/...",
Title = "Conference",
Start = new DateTime(2025, 11, 15, 0, 0, 0, DateTimeKind.Utc),
End = new DateTime(2025, 11, 16, 0, 0, 0, DateTimeKind.Utc),
AllDay = true,
Description = "Annual tech conference",
});
Events.UpdateAsync
Updates an existing event. For an occurrence of a recurring series, set RecurringEventId, and use UpdateMode to choose which occurrences change: this, following or all. See PUT /event.
Method: client.Events.UpdateAsync(EventUpdateData data, CancellationToken ct = default)
Returns: Task<CalendarEvent>
Provider, CalendarId and EventId are required, plus RecurringEventId and UpdateMode for recurring events. EventUpdateData extends EventCreateData, whose Title, Start and End are not nullable and are always sent — set them to the values the event should keep, even when you only change other properties.
Usage:
// Update a simple event
var updatedEvent = await client.Events.UpdateAsync(new EventUpdateData
{
Provider = Provider.Google,
CalendarId = "primary",
EventId = "event123abc",
Title = "Updated Team Meeting",
Start = new DateTime(2025, 11, 1, 14, 0, 0, DateTimeKind.Utc),
End = new DateTime(2025, 11, 1, 15, 0, 0, DateTimeKind.Utc),
});
// Update a single instance of a recurring event
var updatedInstance = await client.Events.UpdateAsync(new EventUpdateData
{
Provider = Provider.Microsoft,
EventId = "instance456",
RecurringEventId = "series123",
CalendarId = "AAMkAGVmMDEz...",
UpdateMode = "this",
Title = "Standup - Special Topic Today",
Start = new DateTime(2025, 11, 1, 9, 0, 0, DateTimeKind.Utc),
End = new DateTime(2025, 11, 1, 10, 0, 0, DateTimeKind.Utc),
});
// Update all future occurrences
var updatedFuture = await client.Events.UpdateAsync(new EventUpdateData
{
Provider = Provider.Apple,
EventId = "recurring-event-id",
CalendarId = "https://caldav.icloud.com/.../calendars/...",
UpdateMode = "following",
Location = "New Conference Room B",
// Title, Start and End are always sent, so pass the event's current values
Title = "Weekly Standup",
Start = new DateTime(2025, 11, 1, 9, 0, 0, DateTimeKind.Utc),
End = new DateTime(2025, 11, 1, 9, 30, 0, DateTimeKind.Utc),
});
Events.DeleteAsync
Deletes an event. For an occurrence of a recurring series, set RecurringEventId, and use DeleteMode to choose which occurrences are deleted: this, following or all. See DELETE /event.
Method: client.Events.DeleteAsync(EventDeleteParams deleteParams, CancellationToken ct = default)
Returns: Task
Provider, CalendarId and EventId are required. RecurringEventId and DeleteMode are optional.
Usage:
// Delete a simple event
await client.Events.DeleteAsync(new EventDeleteParams
{
Provider = Provider.Google,
CalendarId = "primary",
EventId = "event123abc",
});
// Delete a single instance of a recurring event
await client.Events.DeleteAsync(new EventDeleteParams
{
Provider = Provider.Microsoft,
CalendarId = "AAMkAGVmMDEz...",
EventId = "instance456",
RecurringEventId = "series123",
DeleteMode = "this",
});
// Delete entire recurring series
await client.Events.DeleteAsync(new EventDeleteParams
{
Provider = Provider.Apple,
CalendarId = "https://caldav.icloud.com/.../calendars/...",
EventId = "recurring-event-id",
DeleteMode = "all",
});
Webhooks API
The client.Webhooks resource lets you subscribe a calendar to change notifications and unsubscribe an existing channel. It corresponds to the /subscribe-webhook and /unsubscribe-webhook endpoints. Connect subscribes and renews channels automatically when a calendar is connected — this resource is for managing a specific channel explicitly.
🔔 Webhooks API Reference
Webhooks.SubscribeWebhookAsync
Subscribes a calendar to change notifications. See POST /subscribe-webhook.
Method: client.Webhooks.SubscribeWebhookAsync(WebhookSubscribeData data, CancellationToken ct = default)
Returns: Task<WebhookSubscribeResponse>
Provider and CalendarId are required. ChannelId is optional and generated by the server when omitted. Expiration is an optional Unix timestamp in milliseconds.
Usage:
var subscription = await client.Webhooks.SubscribeWebhookAsync(new WebhookSubscribeData
{
Provider = Provider.Google,
CalendarId = "work@company.com",
ChannelId = "my-channel-123",
});
Webhooks.UnsubscribeWebhookAsync
Removes an existing webhook subscription. See POST /unsubscribe-webhook.
Method: client.Webhooks.UnsubscribeWebhookAsync(WebhookUnsubscribeData data, CancellationToken ct = default)
Returns: Task<WebhookUnsubscribeResponse>
Provider and ChannelId are required. ResourceId is the provider resource ID returned by SubscribeWebhookAsync, where the provider uses one.
Usage:
await client.Webhooks.UnsubscribeWebhookAsync(new WebhookUnsubscribeData
{
Provider = Provider.Google,
ChannelId = "my-channel-123",
ResourceId = "resource-abc",
});