Moorsyl Docs

Dart SDK

Official Dart and Flutter client for the Moorsyl API.

The Moorsyl Dart SDK is built on Dio and provides typed request/response models for all API endpoints. It supports Dart and Flutter across Android, iOS, web, macOS, Linux, and Windows.

Installation

pubspec.yaml
dependencies:
  moorsyl: ^1.0.2

Then run:

dart pub get
# or for Flutter projects
flutter pub get

Initialization

import 'package:moorsyl/moorsyl.dart';

final client = Moorsyl();
client.setApiKey('ApiKey', 'sk_live_...');

The SDK defaults to https://api.moorsyl.com/api with a 5 s connect timeout and 3 s receive timeout. No additional configuration is required for production use.

Send an SMS

Requires a secret key (sk_…). See API Keys.

import 'package:dio/dio.dart';
import 'package:moorsyl/moorsyl.dart';

final client = Moorsyl();
client.setApiKey('ApiKey', 'sk_live_...');

final smsApi = client.getSMSApi();

try {
  final response = await smsApi.smsSend(
    smsSendRequest: SmsSendRequest((b) => b
      ..to = '+22236551999'
      ..from = 'MyBrand'
      ..body = 'Your order #1042 has been shipped.'),
  );

  print('Accepted: ${response.data?.accepted}');
  print('Message ID: ${response.data?.messageId}');
  print('Idempotency key: ${response.data?.idempotencyKey}');
} on DioException catch (e) {
  print('Error ${e.response?.statusCode}: ${e.response?.data}');
}

Supply idempotencyKey to prevent duplicate sends on retries:

SmsSendRequest((b) => b
  ..to = '+22236551999'
  ..from = 'MyBrand'
  ..body = 'Your code is 847291'
  ..idempotencyKey = 'otp-user42-20240101T120000')

Phone Verification

Use a publishable key (pk_…) so this code can run safely in a mobile app. See API Keys.

final client = Moorsyl();
client.setApiKey('ApiKey', 'pk_live_...');

final verifyApi = client.getVerifyApi();

Send a verification code

final sendResponse = await verifyApi.verifySend(
  verifySendRequest: VerifySendRequest((b) => b..to = '+22236551999'),
);

final verificationId = sendResponse.data?.verificationId;
// store verificationId — you'll need it for the next step

Check the code

final checkResponse = await verifyApi.verifyCheck(
  verifyCheckRequest: VerifyCheckRequest((b) => b
    ..verificationId = verificationId!
    ..code = userEnteredCode),
);

final status = checkResponse.data?.status.name; // 'approved' or 'denied'

if (status == 'approved') {
  // phone is verified — proceed
}

Full flow

Verify a phone number (Dart)
import 'package:dio/dio.dart';
import 'package:moorsyl/moorsyl.dart';

Future<void> verifyPhoneNumber(String phoneNumber, String userCode) async {
  final client = Moorsyl();
  client.setApiKey('ApiKey', 'pk_live_...');

  final verifyApi = client.getVerifyApi();

  try {
    // Step 1 — send the code
    final sendResponse = await verifyApi.verifySend(
      verifySendRequest: VerifySendRequest((b) => b..to = phoneNumber),
    );
    final verificationId = sendResponse.data!.verificationId;

    // Step 2 — check the code the user entered
    final checkResponse = await verifyApi.verifyCheck(
      verifyCheckRequest: VerifyCheckRequest((b) => b
        ..verificationId = verificationId
        ..code = userCode),
    );

    if (checkResponse.data?.status.name == 'approved') {
      print('Phone verified!');
    } else {
      print('Invalid or expired code.');
    }
  } on DioException catch (e) {
    print('Error ${e.response?.statusCode}: ${e.response?.data}');
  }
}

Error handling

All API methods throw DioException on network or API errors:

try {
  // any SDK call
} on DioException catch (e) {
  print('Status: ${e.response?.statusCode}');
  print('Body:   ${e.response?.data}');
}

Common status codes are documented on the SMS and Verify pages.

On this page