> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sapt.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Media retention and cleanup

> Delete clips after publication, and understand which files stay in the asset library.

For automated clip publishing with short retention, use the social streaming
upload, attach its handle when creating the post, and delete the Sapt post after
confirmed publication and your retention period. This flow stores files with the
post so post deletion can remove them.

<Warning>
  Media imported into the asset library has a separate lifecycle. Deleting a post, its media
  attachment, or a CMS content item does not delete the referenced library file. Delete it
  separately with `DELETE /projects/{projectId}/assets/{assetId}` after every consumer has finished
  using it. This call deletes the file even if other records still reference it.
</Warning>

## What each delete operation removes

| Operation | Removes | Keeps |
| - | - | - |
| `DELETE /socials/posts/{projectId}/{postId}` | Sapt post record, media attachments, and files owned by that post, including its uploaded cover | Referenced library assets and the post already published on the social platform |
| `DELETE /socials/posts/{projectId}/{postId}/media/{mediaId}` | One media attachment and its file when owned by that post | The Sapt post, referenced library assets, and the published platform post |
| `DELETE /projects/{projectId}/cms/items/{contentItemId}`, MCP `deleteContent`, or workflow `delete_cms_content` | CMS content record | Referenced library assets and scheduled-post records |
| `DELETE /projects/{projectId}/assets/{assetId}` | Library file and asset record | Content and post records; references to that file can become unavailable |

These IDs are different: a CMS content ID, Sapt scheduled-post ID, media attachment
ID, and library asset ID identify different resources. Use the `data.post.id`
returned by the social create-post endpoint for post cleanup.

## Delete a clip 24 hours after publication

1. [Stream the clip](/docs/mintlify/social/media#streaming-upload) with
   `PUT /socials/media/{projectId}/stream-upload`. Save the returned `data.handle`.
2. [Create the post](/docs/mintlify/social/scheduling#schedule-a-post) with
   `POST /socials/posts/{projectId}`, passing the handle in `uploadedHandles`.
   Save `data.post.id` in your cleanup job.
3. [Track delivery](/docs/mintlify/social/publishing#track-delivery) until
   `status` is `published`. Calculate the cleanup time from `publishedAt`, not
   `scheduledFor` or the time you submitted the post. If `publishedAt` is missing,
   investigate before deleting.
4. At least 24 hours after `publishedAt`, delete the Sapt post. Save any permalink
   or post details your application needs before deletion.

Check publication:

```bash theme={null}
curl --fail-with-body \
  "https://api.sapt.ai/socials/posts/$PROJECT_ID/$POST_ID/status" \
  -H "Authorization: ApiKey $SAPT_API_KEY"
```

The response's `data` contains `status`, `publishedAt`, `permalink`, and
`errorMessage`. A queued or processing post is not ready for cleanup. Keep failed
posts if you intend to retry publication.

After the retention period, delete:

```bash theme={null}
curl --fail-with-body -X DELETE \
  "https://api.sapt.ai/socials/posts/$PROJECT_ID/$POST_ID" \
  -H "Authorization: ApiKey $SAPT_API_KEY"
```

A successful deletion returns HTTP `200`:

```json theme={null}
{ "success": true }
```

This leaves the published social-platform post in place. Sapt does not
automatically apply a 24-hour retention policy; your application schedules this
cleanup. If you also created a separate CMS content item, removing the scheduled
post does not delete that CMS item.

### Handle cleanup failures

Record the delete response and keep failed cleanup jobs visible. A `404` says the
post record is missing; it does not verify that its files were removed. If a
delete fails or times out and a later attempt returns `404`, treat storage cleanup
as unverified and contact support with the project ID, post ID, and original file
URLs. Do not silently mark that sequence as successful cleanup.

## Clips saved by URL into the library

The Sapt MCP `save` tool accepts media URLs and copies them into the asset library.
The post then references those library assets. This save interface has no
reference-only option, and the deletion calls above leave those files intact.

For future clips that should follow the post's lifetime, use the streaming flow
above. If your source is a URL, your application can download the clip and upload
its bytes through the streaming endpoint.

For URL-imported clips, your cleanup job can keep using the library:

1. Store each clip's library asset ID before deleting its content or post records.
   If you only have the stored URL, [list library assets](/docs/mintlify/api/cms-assets#find-library-assets)
   and match the returned `url`. Use the asset's `id`, not the media attachment ID.
2. Wait until all destinations that use the clip have published and the retention
   period has passed. Keep files needed by pending posts, retries, or other content.
3. Delete the scheduled-post record with the social DELETE endpoint above. Delete
   its CMS item too if your pipeline created one:

```bash theme={null}
curl --fail-with-body -X DELETE \
  "https://api.sapt.ai/projects/$PROJECT_ID/cms/items/$CONTENT_ITEM_ID" \
  -H "Authorization: ApiKey $SAPT_API_KEY"
```

4. Delete the library asset:

```bash theme={null}
curl --fail-with-body -X DELETE \
  "https://api.sapt.ai/projects/$PROJECT_ID/assets/$ASSET_ID" \
  -H "Authorization: ApiKey $SAPT_API_KEY"
```

Asset deletion requires `assets:manage` and returns HTTP `200` with
`{"deletedCount":1}`, or `{"deletedCount":0}` when already absent from this
project. Retry a failed asset deletion using the same ID. CMS deletion returns
`404` for an already-missing item; that does not replace the separate asset-delete
call. These calls do not retract the published platform post.

There is no dedicated library-delete workflow action; API clients can call the
REST endpoint directly. See [CMS and asset APIs](/docs/mintlify/api/cms-assets)
for permissions, pagination, and response details.
