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

# Create or Update Company

> Creates or updates a company using its domain as the lookup key. If a company with the given domain exists for this client, it will be updated with the provided fields. Otherwise, a new company is created.



## OpenAPI

````yaml PUT /public/v2/companies
openapi: 3.0.3
info:
  title: RevyOps API
  version: 1.0.0
servers:
  - url: https://app.revyops.com/api
security:
  - ApiKeyAuth: []
paths:
  /public/v2/companies:
    put:
      tags:
        - public
      description: >-
        Creates or updates a company using its domain as the lookup key. If a
        company with the given domain exists for this client, it will be updated
        with the provided fields. Otherwise, a new company is created.
      operationId: Upsert company (v2)
      parameters:
        - in: query
          name: domain
          schema:
            type: string
          description: >-
            Domain to look up. If a company with this domain exists it will be
            updated; otherwise a new company is created.
          required: true
        - in: query
          name: structure
          schema:
            type: string
            enum:
              - FLAT
              - NESTED
            default: NESTED
          description: >-
            Format of custom fields in response. NESTED returns array of objects
            with id, field_name, field_value. FLAT returns object with field
            names as keys.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Company'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Company'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Company'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Company'
          description: OK. The company already existed and was updated.
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Company'
          description: Created. The company did not exist and was created.
        '400':
          description: Bad Request. Invalid data or missing query parameter.
        '403':
          description: Forbidden. Missing authentication credentials or invalid API key.
        '409':
          description: >-
            Conflict. A company with this domain already exists for this client
            (race condition).
        '422':
          description: >-
            Unprocessable Entity. Custom field(s) not defined in the master
            schema.
        '500':
          description: Internal Server Error. An unexpected error occurred on the server.
components:
  schemas:
    Company:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        updated_time:
          type: string
          format: date-time
          readOnly: true
        domain:
          type: string
        name:
          type: string
        company_status:
          type: string
        company_custom_fields:
          type: array
          items:
            $ref: '#/components/schemas/CompanyCustomFields'
        previous_status:
          type: string
          readOnly: true
          nullable: true
        status_changed_at:
          type: string
          format: date-time
          readOnly: true
          nullable: true
      required:
        - domain
        - id
        - previous_status
        - status_changed_at
        - updated_time
    CompanyCustomFields:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
        updated_time:
          type: string
          format: date-time
          readOnly: true
        field_name:
          type: string
        field_value:
          type: string
          maxLength: 2500
      required:
        - field_name
        - field_value
        - id
        - updated_time
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````