> For the complete documentation index, see [llms.txt](https://docs.mediarithmics.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mediarithmics.io/api-reference/datamart-privacy/cleaning-rules.md).

# Cleaning Rules

Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.

Relevant documentation:

* [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)

## GET /datamarts/{datamart\_id}/cleaning\_rules/{rule\_id}/content\_filter

> Get a user activity content filter

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules/{rule_id}/content_filter":{"get":{"description":"","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/UserEventContentFilterPublicResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"tags":["Cleaning Rules"],"operationId":"getContentFilter","parameters":[{"schema":{"type":"integer","format":"int64"},"required":true,"explode":false,"name":"datamart_id","style":"simple","in":"path"},{"name":"rule_id","explode":false,"style":"simple","required":true,"schema":{"type":"integer","format":"int64"},"in":"path"}],"summary":"Get a user activity content filter"}}},"components":{"schemas":{"UserEventContentFilterPublicResource":{"discriminator":{"propertyName":"content_type","mapping":{"EVENT_NAME_FILTER":"#/components/schemas/EventNameFilterPublicResource"}},"oneOf":[{"$ref":"#/components/schemas/EventNameFilterPublicResource"}],"properties":{"content_type":{"type":"string","enum":["EVENT_NAME_FILTER"]}},"required":["content_type"]},"EventNameFilterPublicResource":{"type":"object","properties":{"filter":{"type":"string","readOnly":false}},"required":["filter"]},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## POST /datamarts/{datamart\_id}/cleaning\_rules/{rule\_id}/content\_filter

> Create a user activity content filter

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules/{rule_id}/content_filter":{"post":{"summary":"Create a user activity content filter","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/UserEventContentFilterPublicResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"requestBody":{"description":"The content filter to create","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserEventContentFilterPublicResource"}}},"required":true},"parameters":[{"in":"path","name":"datamart_id","style":"simple","required":true,"schema":{"type":"integer","format":"int64"},"explode":false},{"name":"rule_id","required":true,"style":"simple","in":"path","schema":{"type":"integer","format":"int64"},"explode":false}],"description":"","tags":["Cleaning Rules"],"operationId":"createContentFilter"}}},"components":{"schemas":{"UserEventContentFilterPublicResource":{"discriminator":{"propertyName":"content_type","mapping":{"EVENT_NAME_FILTER":"#/components/schemas/EventNameFilterPublicResource"}},"oneOf":[{"$ref":"#/components/schemas/EventNameFilterPublicResource"}],"properties":{"content_type":{"type":"string","enum":["EVENT_NAME_FILTER"]}},"required":["content_type"]},"EventNameFilterPublicResource":{"type":"object","properties":{"filter":{"type":"string","readOnly":false}},"required":["filter"]},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## PUT /datamarts/{datamart\_id}/cleaning\_rules/{rule\_id}/content\_filter

> Update a user activity content filter

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules/{rule_id}/content_filter":{"put":{"description":"","requestBody":{"description":"The user activity content filter to update","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UserEventContentFilterPublicResource"}}},"required":true},"summary":"Update a user activity content filter","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/UserEventContentFilterPublicResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"operationId":"updateContentFilter","parameters":[{"name":"datamart_id","in":"path","explode":false,"required":true,"style":"simple","schema":{"type":"integer","format":"int64"}},{"style":"simple","name":"rule_id","schema":{"type":"integer","format":"int64"},"explode":false,"in":"path","required":true}],"tags":["Cleaning Rules"]}}},"components":{"schemas":{"UserEventContentFilterPublicResource":{"discriminator":{"propertyName":"content_type","mapping":{"EVENT_NAME_FILTER":"#/components/schemas/EventNameFilterPublicResource"}},"oneOf":[{"$ref":"#/components/schemas/EventNameFilterPublicResource"}],"properties":{"content_type":{"type":"string","enum":["EVENT_NAME_FILTER"]}},"required":["content_type"]},"EventNameFilterPublicResource":{"type":"object","properties":{"filter":{"type":"string","readOnly":false}},"required":["filter"]},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## DELETE /datamarts/{datamart\_id}/cleaning\_rules/{rule\_id}/content\_filter

> Delete a user activity content filter

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules/{rule_id}/content_filter":{"delete":{"parameters":[{"explode":false,"schema":{"type":"integer","format":"int64"},"style":"simple","required":true,"name":"datamart_id","in":"path"},{"required":true,"explode":false,"in":"path","style":"simple","schema":{"type":"integer","format":"int64"},"name":"rule_id"}],"operationId":"deleteContentFilter","tags":["Cleaning Rules"],"responses":{"200":{"$ref":"#/components/responses/simple"},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"summary":"Delete a user activity content filter","description":""}}},"components":{"responses":{"simple":{"description":"Success response","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]}},"required":["status"]}}}},"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}},"schemas":{"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}}}}
```

## GET /datamarts/{datamart\_id}/cleaning\_rules

> Get cleaning rules

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules":{"get":{"responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"first_result":{"type":"integer"},"total":{"type":"integer"},"data":{"type":"array","items":{"$ref":"#/components/schemas/CleaningRulePublicResource"}},"max_results":{"type":"integer"},"status":{"type":"string","enum":["ok"]},"count":{"type":"integer"}},"required":["count","data","first_result","max_results","status","total"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"parameters":[{"style":"simple","explode":false,"in":"path","name":"datamart_id","required":true,"schema":{"type":"integer","format":"int64"}},{"required":false,"schema":{"type":"boolean"},"explode":true,"style":"form","in":"query","description":"Should retrieve only the archived cleaning rules","name":"archived"},{"style":"form","name":"type","schema":{"$ref":"#/components/schemas/CleaningRuleType"},"explode":true,"description":"The Cleaning Rule type","in":"query","required":false},{"description":"The status of the cleaning rule (DRAFT, LIVE, ARCHIVED)","in":"query","schema":{"$ref":"#/components/schemas/CleaningRuleStatus"},"name":"status","style":"form","explode":true,"required":false},{"description":"Offset from which the search must be performed","name":"first_result","style":"form","required":false,"explode":true,"schema":{"type":"integer","format":"int32"},"in":"query"},{"required":false,"explode":true,"name":"max_results","schema":{"type":"integer","format":"int32"},"style":"form","description":"Number of maximum items that shall be return by this search","in":"query"}],"tags":["Cleaning Rules"],"summary":"Get cleaning rules","description":"","operationId":"getCleaningRules"}}},"components":{"schemas":{"CleaningRulePublicResource":{"discriminator":{"propertyName":"type","mapping":{"USER_EVENT_CLEANING_RULE":"#/components/schemas/UserEventCleaningRulePublicResource","USER_PROFILE_CLEANING_RULE":"#/components/schemas/UserProfileCleaningRulePublicResource"}},"oneOf":[{"$ref":"#/components/schemas/UserEventCleaningRulePublicResource"},{"$ref":"#/components/schemas/UserProfileCleaningRulePublicResource"}],"properties":{"type":{"type":"string","enum":["USER_EVENT_CLEANING_RULE","USER_PROFILE_CLEANING_RULE"]}},"required":["type"]},"UserEventCleaningRulePublicResource":{"type":"object","properties":{"action":{"$ref":"#/components/schemas/CleaningRuleAction"},"activity_type_filter":{"$ref":"#/components/schemas/UserActivityType"},"status":{"$ref":"#/components/schemas/CleaningRuleStatus"},"life_duration":{"type":"string","description":"A valid ISO 8601 Period String","readOnly":false},"archived":{"type":"boolean","default":false,"readOnly":false},"id":{"type":"string","readOnly":true},"channel_filter":{"type":"string","readOnly":false},"datamart_id":{"type":"string","readOnly":true}},"required":["action","archived","datamart_id","id","status"]},"CleaningRuleAction":{"type":"string","enum":["KEEP","DELETE"],"readOnly":false},"UserActivityType":{"type":"string","enum":["ALL","USER_PLATFORM","TOUCH","SITE_VISIT","APP_VISIT","CTV_VISIT","EMAIL","DISPLAY_AD","STOPWATCH","STAGING_AREA","RECOMMENDER","USER_SCENARIO_START","USER_SCENARIO_STOP","USER_SCENARIO_NODE_ENTER","USER_SCENARIO_NODE_EXIT"],"readOnly":false},"CleaningRuleStatus":{"type":"string","enum":["DRAFT","LIVE","ARCHIVED"],"readOnly":false},"UserProfileCleaningRulePublicResource":{"type":"object","properties":{"datamart_id":{"type":"string","readOnly":true},"archived":{"type":"boolean","default":false,"readOnly":false},"action":{"$ref":"#/components/schemas/CleaningRuleAction"},"life_duration":{"type":"string","description":"A valid ISO 8601 Period String","readOnly":false},"compartment_filter":{"type":"string","readOnly":false},"status":{"$ref":"#/components/schemas/CleaningRuleStatus"},"id":{"type":"string","readOnly":true}},"required":["action","archived","datamart_id","id","status"]},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]},"CleaningRuleType":{"type":"string","enum":["USER_EVENT_CLEANING_RULE","USER_PROFILE_CLEANING_RULE"],"readOnly":false}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## POST /datamarts/{datamart\_id}/cleaning\_rules

> Create a cleaning rule

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules":{"post":{"summary":"Create a cleaning rule","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/CleaningRulePublicResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"parameters":[{"required":true,"explode":false,"style":"simple","name":"datamart_id","schema":{"type":"integer","format":"int64"},"in":"path"}],"operationId":"createCleaningRule","description":"","tags":["Cleaning Rules"],"requestBody":{"description":"The cleaning rule to create","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CleaningRulePublicResource"}}},"required":true}}}},"components":{"schemas":{"CleaningRulePublicResource":{"discriminator":{"propertyName":"type","mapping":{"USER_EVENT_CLEANING_RULE":"#/components/schemas/UserEventCleaningRulePublicResource","USER_PROFILE_CLEANING_RULE":"#/components/schemas/UserProfileCleaningRulePublicResource"}},"oneOf":[{"$ref":"#/components/schemas/UserEventCleaningRulePublicResource"},{"$ref":"#/components/schemas/UserProfileCleaningRulePublicResource"}],"properties":{"type":{"type":"string","enum":["USER_EVENT_CLEANING_RULE","USER_PROFILE_CLEANING_RULE"]}},"required":["type"]},"UserEventCleaningRulePublicResource":{"type":"object","properties":{"action":{"$ref":"#/components/schemas/CleaningRuleAction"},"activity_type_filter":{"$ref":"#/components/schemas/UserActivityType"},"status":{"$ref":"#/components/schemas/CleaningRuleStatus"},"life_duration":{"type":"string","description":"A valid ISO 8601 Period String","readOnly":false},"archived":{"type":"boolean","default":false,"readOnly":false},"id":{"type":"string","readOnly":true},"channel_filter":{"type":"string","readOnly":false},"datamart_id":{"type":"string","readOnly":true}},"required":["action","archived","datamart_id","id","status"]},"CleaningRuleAction":{"type":"string","enum":["KEEP","DELETE"],"readOnly":false},"UserActivityType":{"type":"string","enum":["ALL","USER_PLATFORM","TOUCH","SITE_VISIT","APP_VISIT","CTV_VISIT","EMAIL","DISPLAY_AD","STOPWATCH","STAGING_AREA","RECOMMENDER","USER_SCENARIO_START","USER_SCENARIO_STOP","USER_SCENARIO_NODE_ENTER","USER_SCENARIO_NODE_EXIT"],"readOnly":false},"CleaningRuleStatus":{"type":"string","enum":["DRAFT","LIVE","ARCHIVED"],"readOnly":false},"UserProfileCleaningRulePublicResource":{"type":"object","properties":{"datamart_id":{"type":"string","readOnly":true},"archived":{"type":"boolean","default":false,"readOnly":false},"action":{"$ref":"#/components/schemas/CleaningRuleAction"},"life_duration":{"type":"string","description":"A valid ISO 8601 Period String","readOnly":false},"compartment_filter":{"type":"string","readOnly":false},"status":{"$ref":"#/components/schemas/CleaningRuleStatus"},"id":{"type":"string","readOnly":true}},"required":["action","archived","datamart_id","id","status"]},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## GET /datamarts/{datamart\_id}/cleaning\_rules/{id}

> Get a cleaning rule with the given id

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules/{id}":{"get":{"tags":["Cleaning Rules"],"parameters":[{"required":true,"in":"path","name":"datamart_id","style":"simple","schema":{"type":"integer","format":"int64"},"explode":false},{"name":"id","required":true,"in":"path","schema":{"type":"integer","format":"int64"},"style":"simple","explode":false},{"required":false,"name":"type","style":"form","schema":{"$ref":"#/components/schemas/CleaningRuleType"},"in":"query","explode":true}],"description":"","operationId":"getCleaningRule","summary":"Get a cleaning rule with the given id","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/CleaningRulePublicResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}}}}},"components":{"schemas":{"CleaningRuleType":{"type":"string","enum":["USER_EVENT_CLEANING_RULE","USER_PROFILE_CLEANING_RULE"],"readOnly":false},"CleaningRulePublicResource":{"discriminator":{"propertyName":"type","mapping":{"USER_EVENT_CLEANING_RULE":"#/components/schemas/UserEventCleaningRulePublicResource","USER_PROFILE_CLEANING_RULE":"#/components/schemas/UserProfileCleaningRulePublicResource"}},"oneOf":[{"$ref":"#/components/schemas/UserEventCleaningRulePublicResource"},{"$ref":"#/components/schemas/UserProfileCleaningRulePublicResource"}],"properties":{"type":{"type":"string","enum":["USER_EVENT_CLEANING_RULE","USER_PROFILE_CLEANING_RULE"]}},"required":["type"]},"UserEventCleaningRulePublicResource":{"type":"object","properties":{"action":{"$ref":"#/components/schemas/CleaningRuleAction"},"activity_type_filter":{"$ref":"#/components/schemas/UserActivityType"},"status":{"$ref":"#/components/schemas/CleaningRuleStatus"},"life_duration":{"type":"string","description":"A valid ISO 8601 Period String","readOnly":false},"archived":{"type":"boolean","default":false,"readOnly":false},"id":{"type":"string","readOnly":true},"channel_filter":{"type":"string","readOnly":false},"datamart_id":{"type":"string","readOnly":true}},"required":["action","archived","datamart_id","id","status"]},"CleaningRuleAction":{"type":"string","enum":["KEEP","DELETE"],"readOnly":false},"UserActivityType":{"type":"string","enum":["ALL","USER_PLATFORM","TOUCH","SITE_VISIT","APP_VISIT","CTV_VISIT","EMAIL","DISPLAY_AD","STOPWATCH","STAGING_AREA","RECOMMENDER","USER_SCENARIO_START","USER_SCENARIO_STOP","USER_SCENARIO_NODE_ENTER","USER_SCENARIO_NODE_EXIT"],"readOnly":false},"CleaningRuleStatus":{"type":"string","enum":["DRAFT","LIVE","ARCHIVED"],"readOnly":false},"UserProfileCleaningRulePublicResource":{"type":"object","properties":{"datamart_id":{"type":"string","readOnly":true},"archived":{"type":"boolean","default":false,"readOnly":false},"action":{"$ref":"#/components/schemas/CleaningRuleAction"},"life_duration":{"type":"string","description":"A valid ISO 8601 Period String","readOnly":false},"compartment_filter":{"type":"string","readOnly":false},"status":{"$ref":"#/components/schemas/CleaningRuleStatus"},"id":{"type":"string","readOnly":true}},"required":["action","archived","datamart_id","id","status"]},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## PUT /datamarts/{datamart\_id}/cleaning\_rules/{id}

> Update a cleaning rule

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules/{id}":{"put":{"summary":"Update a cleaning rule","responses":{"200":{"description":"Success !","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]},"data":{"$ref":"#/components/schemas/CleaningRulePublicResource"}},"required":["data","status"]}}}},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"requestBody":{"description":"The cleaning rule to update","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CleaningRulePublicResource"}}},"required":true},"parameters":[{"schema":{"type":"integer","format":"int64"},"in":"path","required":true,"explode":false,"name":"datamart_id","style":"simple"},{"style":"simple","explode":false,"required":true,"in":"path","schema":{"type":"integer","format":"int64"},"name":"id"}],"operationId":"updateCleaningRule","tags":["Cleaning Rules"],"description":""}}},"components":{"schemas":{"CleaningRulePublicResource":{"discriminator":{"propertyName":"type","mapping":{"USER_EVENT_CLEANING_RULE":"#/components/schemas/UserEventCleaningRulePublicResource","USER_PROFILE_CLEANING_RULE":"#/components/schemas/UserProfileCleaningRulePublicResource"}},"oneOf":[{"$ref":"#/components/schemas/UserEventCleaningRulePublicResource"},{"$ref":"#/components/schemas/UserProfileCleaningRulePublicResource"}],"properties":{"type":{"type":"string","enum":["USER_EVENT_CLEANING_RULE","USER_PROFILE_CLEANING_RULE"]}},"required":["type"]},"UserEventCleaningRulePublicResource":{"type":"object","properties":{"action":{"$ref":"#/components/schemas/CleaningRuleAction"},"activity_type_filter":{"$ref":"#/components/schemas/UserActivityType"},"status":{"$ref":"#/components/schemas/CleaningRuleStatus"},"life_duration":{"type":"string","description":"A valid ISO 8601 Period String","readOnly":false},"archived":{"type":"boolean","default":false,"readOnly":false},"id":{"type":"string","readOnly":true},"channel_filter":{"type":"string","readOnly":false},"datamart_id":{"type":"string","readOnly":true}},"required":["action","archived","datamart_id","id","status"]},"CleaningRuleAction":{"type":"string","enum":["KEEP","DELETE"],"readOnly":false},"UserActivityType":{"type":"string","enum":["ALL","USER_PLATFORM","TOUCH","SITE_VISIT","APP_VISIT","CTV_VISIT","EMAIL","DISPLAY_AD","STOPWATCH","STAGING_AREA","RECOMMENDER","USER_SCENARIO_START","USER_SCENARIO_STOP","USER_SCENARIO_NODE_ENTER","USER_SCENARIO_NODE_EXIT"],"readOnly":false},"CleaningRuleStatus":{"type":"string","enum":["DRAFT","LIVE","ARCHIVED"],"readOnly":false},"UserProfileCleaningRulePublicResource":{"type":"object","properties":{"datamart_id":{"type":"string","readOnly":true},"archived":{"type":"boolean","default":false,"readOnly":false},"action":{"$ref":"#/components/schemas/CleaningRuleAction"},"life_duration":{"type":"string","description":"A valid ISO 8601 Period String","readOnly":false},"compartment_filter":{"type":"string","readOnly":false},"status":{"$ref":"#/components/schemas/CleaningRuleStatus"},"id":{"type":"string","readOnly":true}},"required":["action","archived","datamart_id","id","status"]},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```

## DELETE /datamarts/{datamart\_id}/cleaning\_rules/{id}

> Delete a cleaning rule

```json
{"openapi":"3.1.1","info":{"title":"mediarithmics openapi API","version":"1.0.0"},"tags":[{"name":"Cleaning Rules","description":"Operations related to **Cleaning Rules**, the configurations that define expiration delays for ingested data, ensuring automatic removal after a specific period to comply with data retention policies and legal requirements. Rules can have **KEEP or DELETE** actions and apply to profiles or events with optional filters by channel, compartment, or activity type. Expiration timestamps are computed at ingestion time and are **non-retroactive**.\n\nRelevant documentation:\n- [Cleaning Rules](https://userguides.mediarithmics.io/settings/datamart/cleaning-rules)\n"}],"servers":[{"url":"http://api.mediarithmics.local/v1","description":"Development server"},{"url":"https://api.mediarithmics.com/v1","description":"Production server"}],"paths":{"/datamarts/{datamart_id}/cleaning_rules/{id}":{"delete":{"parameters":[{"style":"simple","name":"datamart_id","explode":false,"schema":{"type":"integer","format":"int64"},"required":true,"in":"path"},{"name":"id","style":"simple","required":true,"explode":false,"schema":{"type":"integer","format":"int64"},"in":"path"},{"schema":{"$ref":"#/components/schemas/CleaningRuleType"},"explode":true,"name":"type","style":"form","required":false,"in":"query"}],"operationId":"deleteCleaningRule","summary":"Delete a cleaning rule","tags":["Cleaning Rules"],"responses":{"200":{"$ref":"#/components/responses/simple"},"400":{"$ref":"#/components/responses/error"},"401":{"$ref":"#/components/responses/error"},"403":{"$ref":"#/components/responses/error"},"404":{"$ref":"#/components/responses/error"},"500":{"$ref":"#/components/responses/error"},"503":{"$ref":"#/components/responses/error"}},"description":""}}},"components":{"schemas":{"CleaningRuleType":{"type":"string","enum":["USER_EVENT_CLEANING_RULE","USER_PROFILE_CLEANING_RULE"],"readOnly":false},"errorResponse":{"type":"object","properties":{"status":{"type":"string","enum":["error"]},"error_code":{"type":"string","enum":["AUTHENTICATION_ERROR","AUTHORIZATION_ERROR","BAD_REQUEST_DATA","BAD_REQUEST_FORMAT","CONSTRAINT_VIOLATION_EXCEPTION","EMAIL_ALREADY_EXISTS","MAC_ERROR","RESOURCE_NOT_FOUND","SERVICE_UNAVAILABLE","TOKEN_ERROR"]},"error_id":{"type":"string"},"error":{"type":"string"}},"required":["error","error_code","error_id","status"]}},"responses":{"simple":{"description":"Success response","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["ok"]}},"required":["status"]}}}},"error":{"description":"Error response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/errorResponse"}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mediarithmics.io/api-reference/datamart-privacy/cleaning-rules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
