---
title: "Update Deal"
method: PATCH
path: "/deals/{deal_id}"
tags: ["Deals"]
---

# Update Deal

`PATCH /deals/{deal_id}`

## Request

- Base URL: `https://be.graph8.com/api/v1`
- URL: `https://be.graph8.com/api/v1/deals/{deal_id}`
- Auth: HTTP bearer

Update a deal (partial update).

Contact operations run in a fixed order within the single transaction:
``remove_contact_ids`` -> ``add_contact_ids`` -> ``contact_roles``. That
order is what makes the useful combinations work:

* a contact linked by ``add_contact_ids`` in THIS request can be given a
  role by ``contact_roles`` in the same call (roles run last);
* an id in both ``remove_contact_ids`` and ``add_contact_ids`` ends up
  linked (add runs after remove), so a role for it still applies;
* an id in ``remove_contact_ids`` and ``contact_roles`` but NOT in
  ``add_contact_ids`` is unlinked by the time roles run, so it is a 422
  naming that id rather than a role written to a row that no longer
  exists.

A ``contact_roles`` entry for a contact that is neither already linked nor
being added is a 422; the whole transaction rolls back, so a partially
applied batch is not a state this endpoint can produce.

``background_tasks`` carries the ``deal.stage_changed`` fan-out only. It is
injected, not a body field, so it does not appear in the OpenAPI schema and
the request contract is unchanged (pinned by
``developer_api/tests/test_deal_stage_events.py``). Publishing there rather
than inline keeps the Redis round trip off the caller's latency budget and
makes "strictly after the commit" structural: the task is queued only after
the session context has exited, and FastAPI attaches background tasks to the
SUCCESS response, so a raise anywhere above publishes nothing.

## Path parameters

- `deal_id` string, required: Deal ID (UUID)

## Headers

- `Authorization` string, nullable
- `X-Target-Org-Id` string, nullable

## Request body

- DealUpdateRequest
  - `expected_revision` integer, nullable: Apply only if the canonical CRM revision still matches; otherwise return 409. Omit for existing PATCH behavior.
  - `name` string, nullable: Deal name
  - `description` string, nullable: Deal description
  - `amount` number, nullable: Deal monetary value
  - `currency` string, nullable: Currency code
  - `stage_id` string, nullable: Stage ID
  - `close_date` string, nullable: Expected close date (ISO 8601)
  - `owner_id` string, nullable: Reassign deal owner (member id, email, or PropelAuth uid). Cannot be cleared.
  - `add_contact_ids` integer[]: mashup_contact_ids to add to the deal (must match the deal's company; idempotent)
  - `remove_contact_ids` integer[]: mashup_contact_ids to remove from the deal (idempotent — unlinked skipped)
  - `contact_roles` object, nullable: Buying-committee roles keyed by mashup_contact_id, e.g. {"5500429": "champion", "5500914": null}. Valid roles: champion, decision_maker, influencer, blocker, coach, end_user. null clears a role. Each id must already be linked to the deal or be present in add_contact_ids in the same request (422 otherwise).

## Response `200`

Successful Response

- ApiResponseDealResponse
  - `data` DealResponse, required
    - `revision` integer, nullable: CRM revision after a conditional update
    - `id` string, nullable
    - `name` string, nullable
    - `description` string, nullable
    - `amount` number, nullable
    - `currency` string, nullable
    - `stage_id` string, nullable
    - `stage_name` string, nullable
    - `pipeline_id` string, nullable
    - `pipeline_name` string, nullable
    - `company_id` unknown
    - `owner_id` string, nullable
    - `owner_name` string, nullable
    - `owner_email` string, nullable
    - `last_activity_at` string, nullable
    - `close_date` string, nullable
    - `created_at` string, nullable
    - `updated_at` string, nullable
    - `closed_lost_reason` string, nullable
    - `contact_count` integer
    - `primary_contact` ContactBrief: Lightweight contact summary embedded in deal responses. `id` is the canonical `mashup_contact_id` (BigInt), matching how contacts are addressed everywhere else in the public API (g8_search_contacts, g8_lookup_person, etc.). `role` is the contact's role within THIS deal (champion / decision_maker / influencer / blocker / coach / end_user) and is null when no role was set.
      - `id` integer, required
      - `name` string, nullable
      - `email` string, nullable
      - `title` string, nullable
      - `role` string, nullable
    - `contacts` ContactBrief[], nullable
      - `id` integer, required
      - `name` string, nullable
      - `email` string, nullable
      - `title` string, nullable
      - `role` string, nullable
  - `pagination` PaginationMeta
    - `page` integer, required: Current page number (1-indexed)
    - `limit` integer, required: Items per page
    - `total` integer, required: Total number of items
    - `has_next` boolean, required: Whether there are more pages
    - `next_cursor` string, nullable: Opaque cursor for the next page; null when there are no more items. Pass it back as the `cursor` query param to fetch the following page without computing page numbers.
    - `total_available` integer, nullable: Search endpoints only: how many records really match, when known. Can be larger than `total`, which is capped at the 10,000 results that can be paged. For company search this is a distinct-company estimate. Null when unknown; absent outside search.
    - `total_is_lower_bound` boolean, nullable: Search endpoints only: true when more records match than `total` shows (the result set is larger than the 10,000 results that can be paged). Absent outside search.
    - `notes` string[], nullable: Search endpoints only: plain-language notes about the result, e.g. that more records match than can be paged, or that a reversed `between` range was put in order.

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/graph8/apis/graph8-developer-api.md) · [All operations](https://skmtc.dev/graph8/apis/graph8-developer-api/llms.txt) · [OpenAPI document](https://skmtc.dev/graph8/apis/graph8-developer-api/revisions/89fc11143b70?raw)
