---
title: "Create a retention rule"
method: POST
path: "/ocs/v2.php/apps/files_retention/api/v1/retentions"
tags: ["api"]
---

# Create a retention rule

`POST /ocs/v2.php/apps/files_retention/api/v1/retentions`

This endpoint requires admin access

## Headers

- `OCS-APIRequest` boolean, required

## Request body

- object
  - `tagid` integer, required — Tag the retention is based on
  - `timeunit` 0 | 1 | 2 | 3, required — Time unit of the retention (days, weeks, months, years)
  - `timeamount` integer, required — Amount of time units that have to be passed
  - `timeafter` 0 | 1 — Whether retention time is based creation time (0) or modification time (1)

## Response `201`

Retention rule created

- object
  - `ocs` object, required
    - `meta` OCSMeta, required
      - `status` string, required
      - `statuscode` integer, required
      - `message` string
      - `totalitems` string
      - `itemsperpage` string
    - `data` Rule, required
      - `id` integer, required
      - `tagid` integer, required
      - `timeunit` 0 | 1 | 2 | 3, required — 0 days, 1 weeks, 2 months, 3 years
      - `timeamount` integer, required
      - `timeafter` 0 | 1, required — 0 creation time, 1 modification time
      - `hasJob` boolean, required

## Other responses

- `400` — At least one of the parameters was invalid
- `401` — Current user is not logged in
- `403` — Logged in account must be an admin

## Changes

- **2025-12-20** `db5a22e1e7d3` — 3 info
  - the request property `timeafter` became optional
  - added the non-success response with the status `401`
  - added the non-success response with the status `403`
- **2025-03-26** `e4e3f2a5e08a` — 2 breaking, 6 warning, 6 info
  - request property `timeafter` was restricted to a list of enum values
  - request property `timeunit` was restricted to a list of enum values
  - added the new `0.00` enum value to the `ocs/data/timeafter` response property for the response status `201`
  - added the new `0.00` enum value to the `ocs/data/timeunit` response property for the response status `201`
  - …10 more
- **2025-03-26** `ae08f25fe8aa` — 7 breaking, 4 warning, 8 info
  - the request property `timeafter` became required
  - removed the enum value `0.00` of the request property `timeafter`
  - removed the enum value `0.00` of the request property `timeunit`
  - removed the enum value `1.00` of the request property `timeafter`
  - …15 more

[Change history](https://skmtc.dev/nextcloud/apis/files-retention/changes/ocs/v2.php/apps/files_retention/api/v1/retentions/post.md)

---

[API](https://skmtc.dev/nextcloud/apis/files-retention.md) · [All operations](https://skmtc.dev/nextcloud/apis/files-retention/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/nextcloud/files-retention/revisions/cc97a071cea0/schema)
