save method

Many Planning Center endpoints allow or require additional relationships and/or included items to be sent with a create/update operation. Since these cannot always be determined by the automatic code generation, they may be included as arguments to the save operation.

if withRelated or withIncluded are specified, the returned map will include json-api compatible relationship / included fields too since some post/patch endpoints may require them

if either of the manual arguments are specified, they will be used as is

Implementation

Future<PlanningCenterApiResponse> save({
  Map<String, PcoResource>? withRelated,
  List<PcoResource>? withIncluded,
}) async {
  if (id == null && !canCreate) {
    return PlanningCenterApiError.messageOnly(
        'Planning Center disallows creating this object through the API');
  }
  if (id != null && !canUpdate) {
    return PlanningCenterApiError.messageOnly(
        'Planning Center disallows updating this object through the API');
  }

  var dataMap =
      toDataMap(withRelated: withRelated, withIncluded: withIncluded);
  var jsonString = json.encode(dataMap);
  return _selfcall(id == null ? 'post' : 'patch', jsonString);
}