---
title: "Update the retention rules for the repository."
method: PATCH
path: "/repos/{owner}/{repo}/retention/"
tags: ["repos"]
---

# Update the retention rules for the repository.

`PATCH /repos/{owner}/{repo}/retention/`

Update the retention rules for the repository.

## Request body

- RepositoryRetentionRulesRequestPatch
  - `retention_count_limit` integer — The maximum X number of packages to retain.
  - `retention_days_limit` integer — The X number of days of packages to retain.
  - `retention_enabled` boolean — If checked, the retention lifecycle rules will be activated for the repository. Any packages that don't match will be deleted automatically, and the rest are retained.
  - `retention_group_by_format` boolean — If checked, retention will apply to packages by package formats rather than across all package formats.For example, when retaining by a limit of 1 and you upload PythonPkg 1.0 and RubyPkg 1.0, no packages are deleted because they are different formats.
  - `retention_group_by_name` boolean — If checked, retention will apply to groups of packages by name rather than all packages.<br>For example, when retaining by a limit of 1 and you upload PkgA 1.0, PkgB 1.0 and PkgB 1.1; only PkgB 1.0 is deleted because there are two (2) PkgBs and one (1) PkgA.
  - `retention_group_by_package_type` boolean — If checked, retention will apply to packages by package type (e.g. by binary, by source, etc.), rather than across all package types for one or more formats. <br>For example, when retaining by a limit of 1 and you upload DebPackage 1.0 and DebSourcePackage 1.0, no packages are deleted because they are different package types, binary and source respectively.
  - `retention_package_query_string` string, nullable — A package search expression which, if provided, filters the packages to be deleted.<br>For example, a search expression of `name:foo` will result in only packages called 'foo' being deleted, or a search expression of `tag:~latest` will prevent any packages tagged 'latest' from being deleted.<br>Refer to the Cloudsmith documentation for package query syntax.
  - `retention_size_limit` integer — The maximum X total size (in bytes) of packages to retain.

## Response `200`

Updated the retention rules for the repository.

- RepositoryRetentionRules
  - `retention_count_limit` integer — The maximum X number of packages to retain.
  - `retention_days_limit` integer — The X number of days of packages to retain.
  - `retention_enabled` boolean — If checked, the retention lifecycle rules will be activated for the repository. Any packages that don't match will be deleted automatically, and the rest are retained.
  - `retention_group_by_format` boolean — If checked, retention will apply to packages by package formats rather than across all package formats.For example, when retaining by a limit of 1 and you upload PythonPkg 1.0 and RubyPkg 1.0, no packages are deleted because they are different formats.
  - `retention_group_by_name` boolean — If checked, retention will apply to groups of packages by name rather than all packages.<br>For example, when retaining by a limit of 1 and you upload PkgA 1.0, PkgB 1.0 and PkgB 1.1; only PkgB 1.0 is deleted because there are two (2) PkgBs and one (1) PkgA.
  - `retention_group_by_package_type` boolean — If checked, retention will apply to packages by package type (e.g. by binary, by source, etc.), rather than across all package types for one or more formats. <br>For example, when retaining by a limit of 1 and you upload DebPackage 1.0 and DebSourcePackage 1.0, no packages are deleted because they are different package types, binary and source respectively.
  - `retention_package_query_string` string, nullable — A package search expression which, if provided, filters the packages to be deleted.<br>For example, a search expression of `name:foo` will result in only packages called 'foo' being deleted, or a search expression of `tag:~latest` will prevent any packages tagged 'latest' from being deleted.<br>Refer to the Cloudsmith documentation for package query syntax.
  - `retention_size_limit` integer — The maximum X total size (in bytes) of packages to retain.

## Other responses

- `400` — Request could not be processed (see detail).
- `404` — Owner namespace or repository not found
- `422` — Missing or invalid parameters (see detail).

---

[API](https://skmtc.dev/cloudsmith/apis/cloudsmith-api-v1.md) · [All operations](https://skmtc.dev/cloudsmith/apis/cloudsmith-api-v1/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/cloudsmith/cloudsmith-api-v1/revisions/4d7879df9b2f/schema)
