liveCreate method
Live create against POST /sdk/links. Requires an API key.
Implementation
Future<CreateOutcome> liveCreate(
Map<String, dynamic> link, {
required String apiKey,
}) async {
final payload = toSdkPayload(link);
final res = await _http.post(
Uri.parse('$apiBase/sdk/links'),
headers: {'content-type': 'application/json', 'x-app-key': apiKey},
body: jsonEncode(payload),
);
final text = res.body;
Map<String, dynamic> body;
try {
body = text.isNotEmpty
? (jsonDecode(text) as Map<String, dynamic>)
: <String, dynamic>{};
} catch (_) {
body = {'raw': text};
}
if (res.statusCode < 200 || res.statusCode >= 300) {
final msg = body['message'] ?? body['error'] ?? (text.isNotEmpty ? text : 'HTTP ${res.statusCode}');
throw Exception('ULink API ${res.statusCode}: $msg');
}
return CreateOutcome(
status: 'created',
shortLink: (body['shortUrl'] as String?) ?? _shortUrlFor(link),
payload: payload,
link: body,
);
}