Mautic API Wrapper for Dart and Flutter
Add this to your package's pubspec.yaml file:
dependencies:
mautic_api: any
Run flutter pub get
on terminal to download and install packages and import on your files:
import 'package:mautic_api/mautic_api.dart';
You can create a new instance of class MauticAPI
with 3 arguments: base_url
, username
and password
:
final api = MauticAPI('https://yourmauticaddress.com', 'username', 'password');
To test your credentials you can call getCurrentUser()
to get your MauticUser
. If the credentials fail the method return null
.
var user = await api.getCurrentUser();
Here a complete example to get current user info:
import 'package:mautic_api/mautic_api.dart';
void main() async {
///
final api =
MauticAPI('https://yourmauticaddress.com', 'username', 'password');
var user = await api.getCurrentUser();
print(user.id);
print(user.firstName);
print(user.lastName);
print(user.email);
print(user.onlineStatus);
}
The class MauticAPI
provides a constructor with 3 arguments:
base_url
: Your Mautic URL (eg: https://yourmauticaddress.com)username
: Your Mautic Usernamepassword
: Your Mautic Password
Sample usage:
var api = MauticAPI('https://yourmauticaddress.com', 'username', 'password');
There are also two optional arguments to handle cache:
localPath
: The Path for cache directory (default:./tmp
)localExpiresMinutes
: Time to Expire cache in minutes (default: 5)
On Flutter you can use the path_provider
package to get default app cache directory.
The class MauticAPI
has following attributes:
/// Request Has Success?
bool hasSuccess = false;
/// Current Mautic Version?
String mauticVersion;
/// Is Data Read from Cache?
bool isCachedData = false;
The class MauticAPI
has following methods:
/// Return Current User
Future<MauticUser> getCurrentUser();
/// Return User by ID
Future<MauticUser> getUserByID(int _id);
/// Return All Users
Future<List<MauticUser>> getUsers();
/// Return Contact by ID
Future<MauticContact> getContactByID(int _id);
/// Return All Contacts
Future<List<MauticContact>> getContacts({ int page = 0, String s = 'email:%@%', String ob = 'last_active', String od = 'desc', int limit = 5});
/// Return the number of identified contacts
Future<int> getTotalContacts();
/// Return the number of pagination of contacts
Future<int> getContactsPagination({int limit = 30});
/// Return All Emails
Future<List<MauticEmail>> getEmails({ int page = 0, String s = '', String ob = 'id', String od = 'desc', int limit = 30});
/// Return Contact by ID
Future<MauticEmail> getEmailByID(int _id);
/// Return the number of emails
Future<int> getTotalEmails();
/// Return the number of pagination of emails
Future<int> getEmailsPagination({int limit = 30});
Class MauticUser
has the following attributes:
/// User ID
final int id;
/// User First Name
final String firstName;
/// User Last Name
final String lastName;
/// User Email
final String email;
/// User Online Status
final String onlineStatus;
Class MauticContact
has the following attributes:
/// Contact ID
final int id;
/// Contact First Name
final String firstName;
/// Contact Last Name
final String lastName;
/// Contact Email
final String email;
/// Contact Points
final int points;
/// Contact Date Added
final DateTime dateAdded;
/// Contact Date Last Active
final DateTime dateLastActive;
/// Contact Date Identified
final DateTime dateIdentified;
/// Return if Contact is Identified
bool get isIdentified;
Class MauticContact
has the following methods:
/// Return Gravatar URL
String gravatarUrl({int size = 96});
Class MauticEmail
has the following attributes:
final int id;
final bool isPublished;
final String name;
final String subject;
final String fromAddress;
final String fromName;
final String replyToAddress;
final String customHtml;
final String plainText;
final String template;
final String emailType;
final String language;
final DateTime publishUp;
final DateTime publishDown;
final int readCount;
final int sentCount;
double readRate;
bool hasTextPlain;