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

# Update the matching opportunity, or create it

> `match=crm_opportunity_id` finds the opportunity by your CRM's id for it, matched as stored (after trimming spaces) or in its other Salesforce form (15 or 18 characters). One matches: it is updated and the answer is 200 with `result: "updated"`. None does: the body is a create and the answer is 201 with `result: "created"`. A CRM id a deleted opportunity holds is a 409. On the update side `account` must be the one the opportunity is on (409 otherwise; an upsert does not move it). Retrying is safe: a retry after a create updates. Of two upserts of one new CRM id in the same form at the same moment, one creates and the other is a 409; retry it to update. Needs opportunities:create and opportunities:update.



## OpenAPI

````yaml /api/statisfy-api.openapi.json put /v1/objects/opportunity/records
openapi: 3.1.0
info:
  description: >-
    The agent-first Statisfy API. Authenticate with an API key (`Authorization:
    Bearer stfy_live_…`), then call `GET /v1/meta/capabilities` to discover
    every operation and its schemas.
  title: Statisfy API
  version: 1.0.0
servers:
  - url: https://api.statisfy.com
    description: Production
security: []
paths:
  /v1/objects/opportunity/records:
    put:
      tags:
        - opportunities
      summary: Update the matching opportunity, or create it
      description: >-
        `match=crm_opportunity_id` finds the opportunity by your CRM's id for
        it, matched as stored (after trimming spaces) or in its other Salesforce
        form (15 or 18 characters). One matches: it is updated and the answer is
        200 with `result: "updated"`. None does: the body is a create and the
        answer is 201 with `result: "created"`. A CRM id a deleted opportunity
        holds is a 409. On the update side `account` must be the one the
        opportunity is on (409 otherwise; an upsert does not move it). Retrying
        is safe: a retry after a create updates. Of two upserts of one new CRM
        id in the same form at the same moment, one creates and the other is a
        409; retry it to update. Needs opportunities:create and
        opportunities:update.
      operationId: opportunities_upsert
      parameters:
        - description: >-
            The key that finds the opportunity to update; its value comes from
            the body
          in: query
          name: match
          required: true
          schema:
            const: crm_opportunity_id
            type: string
      requestBody:
        content:
          application/json:
            schema:
              additionalProperties: true
              properties:
                account:
                  default: null
                  description: 'Required: the id of the account the opportunity is on'
                  title: Account
                  type: string
                amount:
                  default: null
                  description: The deal's value
                  title: Amount
                  type: number
                close_date:
                  default: null
                  description: YYYY-MM-DD
                  format: date
                  title: Close Date
                  type: string
                crm_opportunity_id:
                  default: null
                  description: The opportunity's id in your CRM
                  title: Crm Opportunity Id
                  type: string
                description:
                  default: null
                  description: Free text
                  title: Description
                  type: string
                fields:
                  anyOf:
                    - additionalProperties: true
                      type: object
                    - type: 'null'
                  default: null
                  description: Custom field keys to values
                  title: Fields
                name:
                  default: null
                  description: The opportunity's name (required on a create)
                  title: Name
                  type: string
                owner:
                  default: null
                  description: The owner's user id
                  title: Owner
                  type: string
                stage:
                  default: null
                  description: >-
                    One of your stages (key or label) where your stage list is
                    set up
                  title: Stage
                  type: string
                type:
                  default: null
                  description: New Business, Renewal, Expansion, ...
                  title: Type
                  type: string
              type: object
        required: false
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpsertedOpportunity'
          description: Successful Response
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpsertedOpportunity'
          description: Created
      security:
        - HTTPBearer: []
components:
  schemas:
    UpsertedOpportunity:
      properties:
        account:
          anyOf:
            - type: string
            - type: 'null'
          description: The id of the account the opportunity is on
          title: Account
        account_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Account Name
        amount:
          anyOf:
            - type: number
            - type: 'null'
          title: Amount
        close_date:
          anyOf:
            - type: string
            - type: 'null'
          title: Close Date
        created_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Created At
        crm_opportunity_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Crm Opportunity Id
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        fields:
          additionalProperties: true
          title: Fields
          type: object
        id:
          title: Id
          type: string
        is_closed:
          default: false
          title: Is Closed
          type: boolean
        is_won:
          default: false
          title: Is Won
          type: boolean
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        owner:
          anyOf:
            - type: string
            - type: 'null'
          description: The owner's user id
          title: Owner
        result:
          enum:
            - created
            - updated
          title: Result
          type: string
        source:
          anyOf:
            - type: string
            - type: 'null'
          title: Source
        stage:
          anyOf:
            - type: string
            - type: 'null'
          title: Stage
        type:
          anyOf:
            - type: string
            - type: 'null'
          title: Type
      required:
        - id
        - result
      title: UpsertedOpportunity
      type: object
  securitySchemes:
    HTTPBearer:
      scheme: bearer
      type: http
      description: >-
        An API key, sent as `Authorization: Bearer stfy_live_…`. See
        [Authentication](/rest-api/authentication) for how to get one and which
        scopes it needs.

````

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