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

# Upsert a referenced row

> Creates or updates a record linking a table row to a document.

The combination of `tableId` and `documentId` is used as the upsert key; `rowId` is optional.

Requires edit access to the document.

Returns the upserted `ReferencedRowInDocument` record.



## OpenAPI

````yaml post /referenced-rows-in-document
openapi: 3.1.0
info:
  title: HERO API
  version: current
  description: |-
    The HERO REST API.

    See https://developers.myhero.so for the rendered docs.
servers:
  - url: https://app.myhero.so
security: []
paths:
  /referenced-rows-in-document:
    post:
      tags:
        - References
      summary: Upsert a referenced row
      description: >-
        Creates or updates a record linking a table row to a document.


        The combination of `tableId` and `documentId` is used as the upsert key;
        `rowId` is optional.


        Requires edit access to the document.


        Returns the upserted `ReferencedRowInDocument` record.
      operationId: upsertReferencedRowInDocument
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                tableId:
                  type: string
                  minLength: 1
                documentId:
                  type: string
                  minLength: 1
                rowId:
                  type: string
              required:
                - tableId
                - documentId
      responses:
        '201':
          description: 201 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      _id:
                        type: string
                      originId:
                        type: string
                      documentId:
                        type: string
                      tableId:
                        type: string
                      rowId:
                        type:
                          - string
                          - 'null'
                      workspaceId:
                        type: string
                      createdAt:
                        type: number
                      updatedAt:
                        type: number
                    required:
                      - _id
                      - documentId
                      - tableId
                      - rowId
                      - workspaceId
                      - createdAt
                      - updatedAt
                required:
                  - data
        '400':
          description: 400 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '403':
          description: 403 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '404':
          description: 404 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
        '500':
          description: 500 response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: |-
                      Error class name (e.g.

                      ValidationError, NotFound)
                  message:
                    type: string
                    description: Human-readable error message
                  details:
                    type: array
                    items: {}
                required:
                  - error
                  - message
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: HERO personal access token

````