This example sends one event to LogZuno's ingestion API from Dart. It is the exact file our snippet tests send to the API before the docs are published.
Requirements
The Dart SDK. dart:io works on the Dart VM and in Flutter apps for mobile and desktop (not Flutter web).
Send an event
// Dart (VM), dart:io only. Run: dart run logzuno.dart
import 'dart:convert';
import 'dart:io';
Future<void> main() async {
final endpoint = Platform.environment['LOGZUNO_ENDPOINT'] ?? 'https://api.logzuno.app/v1';
final client = HttpClient()..connectionTimeout = const Duration(seconds: 10);
final request = await client.postUrl(Uri.parse('$endpoint/log'));
request.headers.set('Authorization', 'Bearer ${Platform.environment['LOGZUNO_API_KEY']}');
request.headers.contentType = ContentType.json;
request.add(utf8.encode(jsonEncode({
'channel': 'signups',
'event': 'User signed up',
'user_id': 'user-123',
'icon': '🎉',
'notify': true,
'tags': {'plan': 'growth', 'source': 'website'},
})));
final response = await request.close();
print('${response.statusCode} ${await response.transform(utf8.decoder).join()}');
client.close();
}Export LOGZUNO_API_KEY and run dart run logzuno.dart. LogZuno answers 202 and the event appears in your project's live feed within seconds. Keep the key in an environment variable or your secrets manager, not in source control.
Notes for Dart
Flutter. Send the same request from your app with an ingest key that has New channels and New groups turned off. For Flutter web, use the http package with the same body and headers.
Close the client. HttpClient keeps connections open; reuse one and close it when the program ends.
Batch. Queue events and send up to 100 at once to /v1/batch.
What the request contains
The body is the same in every language: a channel and an event, and optionally user_id, group_id, description, icon, notify and tags. All fields, limits and response codes are in sending events and the ingestion API reference.