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

# Delete a media file

> Delete a file from the media library and from the posts that hold it.

> [!NOTE]
>
> Needs `media:delete`, and a role in the workspace that can delete media. See [Permissions](/docs/essentials/authentication.md#permissions).

Deletes the file and its copies, and takes it out of every post that holds it. What was already published stays on the networks. This can't be undone.

A file an upcoming post still needs isn't deleted: a post that is scheduled, queued, waiting for approval or repeating. The answer is `422`, and its message names up to 3 of those posts. Let them publish first, or take the file off them, then delete it. A file still being made (`is_processing`) isn't deleted either; if it fails to generate, it goes on its own.

## Errors

| Status | `error` | When | Retry? |
| - | - | - | - |
| 401 | | No API key, or not a valid one. | No: fix the key. |
| 403 | | The key lacks `media:delete`, or its user is inactive. | No: grant it in Settings → API. |
| 403 | | Your role in the workspace can't delete media. | No. |
| 404 | | No file with that id in the workspaces the key can reach. | No. |
| 422 | | An upcoming post still needs the file, or it is still being made. Nothing was deleted. | After the posts go out, or once it is ready. |
| 429 | | More than 60 requests a minute. | Yes, after `Retry-After` seconds. |

## Related

* [Update a post](/docs/api-reference/posts/update.md): take the file off a post first.
* [List media](/docs/api-reference/media/list.md): the library.


## OpenAPI

````yaml DELETE /media/{media_id}
openapi: 3.0.3
info:
  title: PostSyncer API
  description: >-
    Post to 12 social networks from your code: posts, media, comments,
    analytics, webhooks and more.
  version: 1.0.0
servers:
  - url: https://postsyncer.com/api/v1
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: The workspaces the key can reach.
  - name: Accounts
    description: Connected social accounts, links to connect more, and disconnecting them.
  - name: Posts
    description: Drafts, scheduled and published posts, approvals and a post's history.
  - name: Post settings
    description: A post's auto-plug, comment moderation and contact collection.
  - name: Media
    description: >-
      The media library: file uploads, URL imports, and reading videos and
      social posts' files.
  - name: Folders
    description: Folders that organise the media library.
  - name: Comments
    description: >-
      Comments on your posts: reading, replying, editing, hiding, deleting and
      syncing them.
  - name: Reviews
    description: Google Business Profile reviews and your replies to them.
  - name: Analytics
    description: Workspace, account and post performance.
  - name: Brand
    description: >-
      A workspace's brand: identity, voice, look, accounts, competitors,
      learnings and rules.
  - name: Labels
    description: Labels used to tag posts.
  - name: Campaigns
    description: Campaigns used to group posts.
  - name: Snippets
    description: Saved snippets and hashtag groups to drop into posts.
  - name: Webhooks
    description: Signed webhook endpoints that get your notification events.
  - name: Billing
    description: >-
      The owner's plan, invoices and the links that pay for, change or cancel
      it.
  - name: Team
    description: A workspace's teammates and invitations, and their roles.
  - name: Notifications
    description: >-
      Your bell and notification settings, and the workspace's Slack, Discord
      and Telegram channels.
  - name: Blog-to-social
    description: Blog feeds that turn a workspace's new articles into posts.
  - name: Products
    description: Products the workspace's posts can promote.
  - name: Contacts
    description: People who commented on the workspace's posts, and the lists they are on.
  - name: Profile
    description: 'The key''s user: their name and sign-in email.'
  - name: API keys
    description: 'Your API keys: listing and deleting them.'
  - name: Agent sign-up
    description: >-
      An AI agent signs a person up with a code emailed to them, and gets their
      first key. No key needed.
paths:
  /media/{media_id}:
    delete:
      tags:
        - Media
      summary: Delete a media file
      description: >-
        Needs `media:delete`. Your role in the workspace must also let you
        delete media. Deletes the file and its copies, and takes it out of every
        post that holds it; what was already published stays on the networks. A
        file an upcoming post still needs (scheduled, queued, waiting for
        approval, or repeating) or that is still being made isn't deleted: the
        answer is `422`. This can't be undone.
      operationId: deleteMedia
      parameters:
        - name: media_id
          in: path
          required: true
          description: The file's id.
          schema:
            type: integer
      responses:
        '200':
          description: The file was deleted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                default:
                  summary: Deleted
                  value:
                    message: Media deleted successfully
        '401':
          $ref: '#/components/responses/Unauthorized401'
        '403':
          description: >-
            The key lacks `media:delete`, its user is inactive, or your role in
            the workspace can't delete media.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missing_permission:
                  summary: The key lacks media:delete
                  value:
                    message: >-
                      This API key does not have the "media:delete" permission.
                      Edit the key in PostSyncer under Settings → API to grant
                      it.
                role:
                  summary: The role can't delete media
                  value:
                    message: >-
                      Your role in the workspace "Halden Coffee" does not allow
                      you to delete media. Ask the workspace owner or a manager
                      to do it, or to change your role.
                inactive_account:
                  summary: The key's user is inactive
                  value:
                    message: Your account is inactive.
        '404':
          $ref: '#/components/responses/NotFound404'
        '422':
          description: >-
            An upcoming post still needs the file, or it is still being made.
            Nothing was deleted. `message` names up to 3 of the posts.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
              examples:
                still_needed:
                  summary: An upcoming post needs it
                  value:
                    message: >-
                      This media is still needed by 1 upcoming post: #4182 "Our
                      spring menu starts today...." (scheduled for Mar 15, 2030
                      9:00 AM). Let them publish first, or remove the media from
                      those posts, then delete it.
                    errors:
                      media:
                        - >-
                          This media is still needed by 1 upcoming post: #4182
                          "Our spring menu starts today...." (scheduled for Mar
                          15, 2030 9:00 AM). Let them publish first, or remove
                          the media from those posts, then delete it.
                still_generating:
                  summary: It is still being made
                  value:
                    message: >-
                      This media is still being generated. It can be deleted
                      once it is ready, or it is removed on its own if
                      generation fails.
                    errors:
                      media:
                        - >-
                          This media is still being generated. It can be deleted
                          once it is ready, or it is removed on its own if
                          generation fails.
        '429':
          $ref: '#/components/responses/RateLimited429'
components:
  schemas:
    Error:
      type: object
      description: >-
        An error answer. Every one has `message`, in plain words; some add an
        `error` code and fields of their own.
      required:
        - message
      properties:
        message:
          type: string
          description: What went wrong and what to do about it.
        error:
          type: string
          description: >-
            A code a few errors add, such as `rate_limited`. See [Handle
            errors](/essentials/error-handling#answers-with-an-error-code).
    ValidationError:
      type: object
      description: '422: the request didn''t pass validation, and nothing changed.'
      required:
        - message
        - errors
      properties:
        message:
          type: string
          description: >-
            The first error and, when there are more, how many: `(and 1 more
            error)`, `(and 2 more errors)`.
        errors:
          type: object
          description: >-
            The messages, by field. A field inside a list is named with dots:
            `accounts.0.id`.
          additionalProperties:
            type: array
            items:
              type: string
  responses:
    Unauthorized401:
      description: No API key, or not a valid one.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            unauthenticated:
              summary: No valid API key
              value:
                message: Unauthenticated.
    NotFound404:
      description: Nothing with that id in the workspaces the key can reach.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            not_found:
              summary: Not found
              value:
                message: Not found.
    RateLimited429:
      description: >-
        More than 60 requests in a minute from this key's user (the API and the
        MCP server share the count). Wait `Retry-After` seconds.
      headers:
        Retry-After:
          description: Seconds until requests are allowed again.
          schema:
            type: integer
        X-RateLimit-Limit:
          description: Requests allowed a minute.
          schema:
            type: integer
        X-RateLimit-Remaining:
          description: Requests left this minute.
          schema:
            type: integer
        X-RateLimit-Reset:
          description: When requests are allowed again, as a Unix timestamp.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            too_many_attempts:
              summary: Too many requests
              value:
                message: Too Many Attempts.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.