getEditLink method

Future<Uri> getEditLink({
  1. required Uri uri,
  2. required String formId,
  3. Map<String, String> headers = const {},
})

Creates and returns a Uri pointing to a Form filled with the Data represented for a given entitiy

headers will be added in addition to ApptiveGridClient.defaultHeaders

Requires Authorization throws Response if the request fails

Implementation

Future<Uri> getEditLink({
  required Uri uri,
  required String formId,
  Map<String, String> headers = const {},
}) async {
  await authenticator.checkAuthentication();

  final url = _generateApptiveGridUri(uri);

  final response = await _client.post(
    url,
    headers: _createHeadersWithDefaults(headers),
    body: jsonEncode({
      'formId': formId,
    }),
  );

  if (response.statusCode >= 400) {
    throw response;
  }

  return Uri.parse(
    ((json.decode(response.body) as Map)['uri'] as String)
        .replaceAll(RegExp('/r/'), '/a/'),
  );
}