createLink method
Makes a link to path (/product) opened with parameters as its
query, and answers its URL, https://<host>/<code>.
title, description and imageUrl (https) are the social preview;
campaign the link's UTM attribution, fixed for its life; name what
the maker sees in the link list; forceRedirect sends an iPhone
without the app straight to the App Store. A parameter may not be a
utm_* key. Throws FFXDynamicLinksNotConfiguredError when off,
FFXValidationError for a bad argument, and the host's problem
otherwise (userMessage is safe to show).
Implementation
Future<Uri> createLink({
required String path,
Map<String, String> parameters = const {},
String? title,
String? description,
String? imageUrl,
FFXLinkCampaign campaign = FFXLinkCampaign.empty,
String? name,
bool forceRedirect = false,
}) async {
final base = _requireBase();
final body = _createBody(
path: path,
parameters: parameters,
title: title,
description: description,
imageUrl: imageUrl,
campaign: campaign,
name: name,
forceRedirect: forceRedirect,
);
final response = await _withRetry(
() => _core.client.post(
_endpoint(base, '/v1/links'),
headers: const {
'content-type': 'application/json',
'accept': 'application/json',
},
body: jsonEncode(body.toJson()),
),
attempts: 2,
maxWaiting: const Duration(seconds: 2),
what: 'create a link',
);
if (response.statusCode != 201 && response.statusCode != 200) {
throw _problemOf(response);
}
final created = _decode(response, PublicCreateDynamicLinkResponse.fromJson);
_log('Made link ${created.shortCode} to $path.');
return _linkUri(base, created.shortCode);
}