upsertTemplate method

Future<Template?> upsertTemplate(
  1. String templateType,
  2. String slug, {
  3. UpsertTemplateRequest? upsertTemplateRequest,
})

Update a template for a given type and slug

Updates the existing template of the given type and slug

Parameters:

  • String templateType (required): The type of template to update

  • String slug (required): The slug of the template to update

  • UpsertTemplateRequest upsertTemplateRequest:

Implementation

Future<Template?> upsertTemplate(
  String templateType,
  String slug, {
  UpsertTemplateRequest? upsertTemplateRequest,
}) async {
  final response = await upsertTemplateWithHttpInfo(
    templateType,
    slug,
    upsertTemplateRequest: upsertTemplateRequest,
  );
  if (response.statusCode >= HttpStatus.badRequest) {
    throw ApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  // When a remote server returns no body with a status of 204, we shall not decode it.
  // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
  // FormatException when trying to decode an empty string.
  if (response.body.isNotEmpty &&
      response.statusCode != HttpStatus.noContent) {
    return await apiClient.deserializeAsync(
      await _decodeBodyBytes(response),
      'Template',
    ) as Template;
  }
  return null;
}