> ## 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.

# Link an Activity to a Deal

> Attach an existing account-level activity to a deal.

Two-way visibility: the activity keeps its account_id, so it remains in the
account timeline AND now appears in the deal timeline.

Errors:
  - 404 if activity or deal not found in this org
  - 409 if activity is already linked to a different deal
  - 422 if the activity's account differs from the deal's account

Attaches an existing account-level activity to a deal via a validated RPC. The activity keeps its `account_id`, so it remains visible in the account timeline **and** now also appears in the deal timeline. If the activity's `account_id` was unset, linking it to the deal backfills that column from the deal's own account — a deal always belongs to one account, so the two links stay consistent.

Linking to a deal is validated, not a raw column write: this endpoint goes through a `SECURITY DEFINER` RPC that enforces the checks below. [Updating an activity's `deal_id`](/api-reference/activities/update-activity) routes through the same RPC; [unlinking a deal](/api-reference/activities/unlink-deal) does not — it's always a plain column write.

### 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                                               |
| --------- | --------------- | --------------------------------------------------------- |
| `id`      | `string` (uuid) | The `activity_id`, echoed back as the RPC's return value. |
| `deal_id` | `string` (uuid) | The deal it's now linked to.                              |

### Errors

| Status                     | Cause                                                                            |
| -------------------------- | -------------------------------------------------------------------------------- |
| `404 Not Found`            | Activity or deal doesn't exist in this org.                                      |
| `409 Conflict`             | Activity is already linked to a *different* deal.                                |
| `422 Unprocessable Entity` | The activity's `account_id` and the deal's `account_id` are both set and differ. |


## OpenAPI

````yaml POST /activities/{activity_id}/link-deal
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:
  /activities/{activity_id}/link-deal:
    post:
      tags:
        - Activities
      summary: Link Activity To Deal
      description: >-
        Attach an existing account-level activity to a deal.


        Two-way visibility: the activity keeps its account_id, so it remains in
        the

        account timeline AND now appears in the deal timeline.


        Errors:
          - 404 if activity or deal not found in this org
          - 409 if activity is already linked to a different deal
          - 422 if the activity's account differs from the deal's account
      operationId: link_activity_to_deal_activities__activity_id__link_deal_post
      parameters:
        - name: activity_id
          in: path
          required: true
          schema:
            type: string
            description: The account-level activity's id to attach to a deal.
            title: Activity Id
          description: The account-level activity's id to attach to a deal.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LinkActivityBody'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    LinkActivityBody:
      properties:
        deal_id:
          type: string
          title: Deal Id
          description: Deal to attach the activity to.
      type: object
      required:
        - deal_id
      title: LinkActivityBody
    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

````