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

# Attach a File to an Entity

> Attach an existing file to a CRM entity.

Creates a `file_attachments` row linking the file to a CRM entity. Attachments are a many-to-many join, not a field on the file — a file can be attached to several entities at once. In practice `entity_type` is one of `deal`, `account`, `contact`, `task`, or `project`, but the database does not constrain the value.

### Auth

Requires a CRM manage [scope](/authentication#scopes) and an active organization on the token. Any `*:manage` scope qualifies — in practice `contacts:manage`, `deals:manage`, `companies:manage`, or `activities:manage`.

### Response

| Field      | Type      | Description               |
| ---------- | --------- | ------------------------- |
| `attached` | `boolean` | Always `true` on success. |

### Errors

| Status            | Cause                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `404 Not Found`   | File doesn't exist (or isn't in this org, or is archived).                                                                                                                                                                                                                                                                                                                                                                             |
| `502 Bad Gateway` | Attaching the same file to the same `(entity_type, entity_id)` pair twice violates a database uniqueness constraint (`file_attachments` has a unique key on `file_id, entity_type, entity_id`); unlike some other endpoints in this API, this one does not translate that into a `409` — it surfaces as a generic `502`. Check [List Files Attached to an Entity](/api-reference/files/by-entity) first if you need idempotent attach. |


## OpenAPI

````yaml POST /files/{file_id}/attach
openapi: 3.1.0
info:
  title: anycrm-api
  version: 0.0.1
servers: []
security: []
tags:
  - name: Customer Intelligence
    description: >-
      Company research and ICP-fit scoring — create a research run, track its
      progress, and read back scored companies as leads.
  - name: Outreach
    description: >-
      The cold-email management console — domains, mailboxes, and campaigns — as
      a thin control plane over the SalesForge stack.
  - name: AnyCard
    description: >-
      Authenticated CRUD for AnyCard, the org's digital business-card /
      lead-capture product.
  - name: AnyCard Events
    description: >-
      Event-attribution analytics for AnyCard — which captured leads converted,
      broken down by source, owner, and deal.
  - name: AnyCard Share Links
    description: >-
      Unauthenticated endpoints reached by anyone who scans a QR code or opens a
      shared AnyCard link.
  - name: AI
    description: >-
      A streaming (SSE) AI chat endpoint with account-commit actions it can take
      on the caller's behalf.
  - name: Analytics Assistant
    description: >-
      The natural-language analytics assistant — a guarded text-to-SQL loop
      (SSE) that answers ad-hoc questions over the org's CRM data as a
      least-privilege, read-only database role.
  - name: Account Readiness
    description: >-
      Account Readiness Profiles — AI-scored signals on whether an account is
      ready for outreach or expansion, computed via a Temporal workflow.
  - name: Integrations
    description: >-
      Pipedream Connect — issuing connect tokens and managing the org's
      connected third-party accounts.
  - name: Feedback
    description: >-
      User-submitted platform feedback (bug reports, feature requests) — global,
      not scoped to one organization.
  - name: Public Media
    description: >-
      Unauthenticated image reads for publicly-embeddable assets (card photos,
      inline email images) — allowlisted by key shape; everything else in the
      storage bucket stays private.
  - name: Service Health
    description: Service liveness.
paths:
  /files/{file_id}/attach:
    post:
      tags:
        - Files
      summary: Attach File
      description: Attach an existing file to a CRM entity.
      operationId: attach_file_files__file_id__attach_post
      parameters:
        - name: file_id
          in: path
          required: true
          schema:
            type: string
            description: UUID of the file to attach to a CRM entity.
            title: File Id
          description: UUID of the file to attach to a CRM entity.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AttachRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  type: boolean
                title: Response Attach File Files  File Id  Attach Post
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    AttachRequest:
      properties:
        entity_type:
          type: string
          title: Entity Type
          description: >-
            CRM entity kind to attach to, e.g. deal, account, contact, task,
            project.
        entity_id:
          type: string
          title: Entity Id
          description: UUID of the entity to attach the file to.
      type: object
      required:
        - entity_type
        - entity_id
      title: AttachRequest
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````