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

# Update Model

> Update an existing model

Patch a model based on its Hightouch ID



## OpenAPI

````yaml https://api.hightouch.io/api/swagger.json patch /models/{modelId}
openapi: 3.0.0
info:
  title: Hightouch API
  version: 1.0.0
  description: Hightouch Public Rest API to access syncs, models, sources and destinations
  contact:
    name: Hightouch
    url: https://hightouch.com
servers:
  - url: https://api.hightouch.com/api/v1
security: []
paths:
  /models/{modelId}:
    patch:
      summary: Update Model
      description: |-
        Update an existing model

        Patch a model based on its Hightouch ID
      operationId: UpdateModel
      parameters:
        - description: The model's ID
          in: path
          name: modelId
          required: true
          schema:
            type: number
            format: double
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ModelUpdate'
            example:
              name: testmodel
              description: Names of all users
              primaryKey: id
              raw:
                sql: select name from users
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/Model'
                  - $ref: '#/components/schemas/ValidateErrorJSON'
                  - $ref: '#/components/schemas/InternalServerError'
              examples:
                Example 1:
                  value:
                    id: 1
                    name: testModel
                    slug: testModel
                    description: Names of all users
                    workspaceId: 1
                    primaryKey: id
                    createdAt: '2022-02-16T21:37:58.510Z'
                    updatedAt: '2022-02-17T23:19:05.000Z'
                    createdBy:
                      id: 1
                      name: Jane Doe
                      email: jane.doe@example.com
                    updatedBy:
                      id: 1
                      name: Jane Doe
                      email: jane.doe@example.com
                    sourceId: 1
                    queryType: raw_sql
                    tags:
                      foo: bar
                    isSchema: false
                    isGeneralModel: false
                    raw:
                      sql: select name from users
                    syncs:
                      - 1
                      - 2
                    lastRunSize: 12345
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '422':
          description: Validation Failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidateErrorJSON'
        '500':
          description: Something went wrong
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerError'
      security:
        - bearerAuth: []
components:
  schemas:
    ModelUpdate:
      description: The input for updating a Model
      properties:
        name:
          type: string
          description: The name of the model
        description:
          type: string
          nullable: true
          description: The description of the model. Null when no description has been set.
        isSchema:
          type: boolean
          description: |-
            If is_schema is true, the model is just used to build other models.
            Either as part of visual querying, or as the root of a visual query.
        visual:
          properties:
            secondaryLabel:
              type: string
            primaryLabel:
              type: string
            filter: {}
            parentId:
              type: number
              format: double
              description: Parent id of the schema that visual query is based on
          required:
            - filter
            - parentId
          type: object
          description: Visual query, used by audience
        custom:
          properties:
            query: {}
          required:
            - query
          type: object
          description: >-
            Custom query for sources that doesn't support sql. For example,
            Airtable.
        table:
          properties:
            name:
              type: string
          required:
            - name
          type: object
          description: Table-based query that fetches on a table instead of SQL
        raw:
          properties:
            sql:
              type: string
          required:
            - sql
          type: object
          description: Standard raw SQL query
        folderId:
          type: string
        primaryKey:
          type: string
          description: >-
            The primary key will be null if the query doesn't get directly
            synced (e.g. a relationship table for visual querying)
        dbt:
          properties:
            modelId:
              type: number
              format: double
              description: Model id that refers to a dbt model
          required:
            - modelId
          type: object
      type: object
      additionalProperties: false
    Model:
      description: >-
        The SQL query that pulls data from your source to send to your
        destination.

        We send your SQL query directly to your source so any SQL that is valid
        for your source (including functions) is valid in Hightouch.
      properties:
        id:
          type: number
          format: double
          description: The id of the model
        name:
          type: string
          description: The name of the model
        slug:
          type: string
          description: The slug of the model
        description:
          type: string
          nullable: true
          description: The description of the model. Null when no description has been set.
        workspaceId:
          type: number
          format: double
          description: The id of the workspace where the model belongs to
        primaryKey:
          type: string
          description: >-
            The primary key will be null if the query doesn't get directly
            synced (e.g. a relationship table for visual querying)
        createdAt:
          type: string
          format: date-time
          description: The timestamp when model was created
        updatedAt:
          type: string
          format: date-time
          description: The timestamp when model was lastly updated
        createdBy:
          allOf:
            - $ref: '#/components/schemas/UserReference'
          nullable: true
          description: The user who created the model, or null if no user was recorded
        updatedBy:
          allOf:
            - $ref: '#/components/schemas/UserReference'
          nullable: true
          description: The user who last updated the model, or null if no user was recorded
        sourceId:
          type: number
          format: double
          description: The id of the source that model is connected to
        queryType:
          type: string
          description: >-
            The type of the query. Available options: custom, raw_sql, tabel,
            dbt and visual.
        tags:
          properties: {}
          additionalProperties:
            type: string
          type: object
          description: The tags of the model
        isSchema:
          type: boolean
          description: |-
            If is_schema is true, the model is just used to build other models.
            Either as part of visual querying, or as the root of a visual query.
        isGeneralModel:
          type: boolean
          description: >-
            If is_general_model is true, the model is not synced. It exposes
            warehouse

            data to Hightouch AI agents and is managed from the schema section.
        syncs:
          items:
            type: number
            format: double
          type: array
          description: The list of id of syncs that uses this model
        visual:
          properties:
            secondaryLabel:
              type: string
            primaryLabel:
              type: string
            filter: {}
            parentId:
              type: number
              format: double
              description: Parent id of the schema that visual query is based on
          required:
            - filter
            - parentId
          type: object
          description: Visual query, used by audience
        custom:
          properties:
            query: {}
          required:
            - query
          type: object
          description: >-
            Custom query for sources that doesn't support sql. For example,
            Airtable.
        table:
          properties:
            name:
              type: string
          required:
            - name
          type: object
          description: Table-based query that fetches on a table instead of SQL
        dbt:
          properties:
            dbtUniqueId:
              type: string
              description: >-
                Unique ID of the model assigned by dbt (usually some combination
                of the schema and table name)
            compiledSql:
              type: string
              description: Compiled SQL in the dbt model
            rawSql:
              type: string
              description: Raw SQL in the dbt model
            database:
              type: string
              description: Name of the database containing the generated table
            schema:
              type: string
              description: Name of the schema containing the generated table
            name:
              type: string
              description: Name of the table generated by the dbt model
            modelId:
              type: number
              format: double
              description: Model id that refer to a dbt model
          required:
            - dbtUniqueId
            - compiledSql
            - rawSql
            - database
            - schema
            - name
            - modelId
          type: object
          description: Query that is based on a dbt model
        dbt_cloud:
          properties:
            dbtUniqueId:
              type: string
              description: >-
                Unique ID of the model assigned by dbt (usually some combination
                of the schema and table name)
            compiledSql:
              type: string
              description: Compiled SQL in the dbt model
            rawSql:
              type: string
            name:
              type: string
              description: Name of the table generated by the dbt model
            modelId:
              type: number
              format: double
              description: Model id that refer to a dbt model
          required:
            - dbtUniqueId
            - compiledSql
            - rawSql
            - name
            - modelId
          type: object
        raw:
          properties:
            sql:
              type: string
          required:
            - sql
          type: object
          description: Standard raw SQL query
        folderId:
          type: string
        lastRunSize:
          type: number
          format: double
          nullable: true
          description: >-
            The number of rows returned by the most recent successful sync run
            of this model.

            Null if the model has never been synced successfully.
        spaceId:
          type: string
          description: >-
            The Space this audience belongs to. Applies only to workspaces with
            Spaces enabled;

            contact Hightouch to enable Spaces and to obtain Space ids.

            Only valid when queryType is "visual". Omitted for models that are
            not in a Space.

            An API key scoped to a Space must set it on create. Read-only after
            creation.
        rowLevelAccessRuleIds:
          items:
            type: string
          type: array
          description: >-
            Row-level access rules attached to this audience. Applies only to
            workspaces with

            Spaces enabled. Only valid when queryType is "visual"; always
            present on an audience.

            When creating an audience in a Space, include one rule from each
            required row-level

            access group on the parent model. Rule ids come from the Spaces
            governance API.

            Read-only after creation.
      required:
        - id
        - name
        - slug
        - description
        - workspaceId
        - primaryKey
        - createdAt
        - updatedAt
        - createdBy
        - updatedBy
        - sourceId
        - queryType
        - tags
        - isSchema
        - isGeneralModel
        - syncs
        - lastRunSize
      type: object
      additionalProperties: false
    ValidateErrorJSON:
      properties:
        message:
          type: string
          enum:
            - Validation failed
          nullable: false
        details:
          properties: {}
          additionalProperties: {}
          type: object
      required:
        - message
        - details
      type: object
      additionalProperties: false
    InternalServerError:
      type: string
      enum:
        - Internal Server Error
      nullable: false
    UserReference:
      description: >-
        The Hightouch user who created or last updated a resource. Changes made
        with

        an API key are attributed to the user who created the key.
      properties:
        id:
          type: number
          format: double
          description: The user's id
        name:
          type: string
          description: The user's name
        email:
          type: string
          description: The user's email address
      required:
        - id
        - name
        - email
      type: object
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Bearer

````