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

# Update variables

> Renames variables or changes their type or value. Renaming rewrites every {{placeholder}} referencing the variable, across text items, library components, variants, and plurals, so existing text keeps resolving. String, number, and hyperlink variables have fixed `data` fields, so sending only some of them leaves the rest as they were; a list or map variable's `data` is its entire value, so what you send replaces it outright. Changing `type` means sending `data` as well, even when the value itself stays the same. Either every update is applied or none is.



## OpenAPI

````yaml openapi.json patch /variables
openapi: 3.0.0
info:
  version: 1.0.0
  title: Ditto API
  description: Programmatically read and write data in your Ditto workspace.
servers:
  - url: https://api.dittowords.com/v2
security: []
paths:
  /variables:
    patch:
      tags:
        - Variables
      summary: Update variables
      description: >-
        Renames variables or changes their type or value. Renaming rewrites
        every {{placeholder}} referencing the variable, across text items,
        library components, variants, and plurals, so existing text keeps
        resolving. String, number, and hyperlink variables have fixed `data`
        fields, so sending only some of them leaves the rest as they were; a
        list or map variable's `data` is its entire value, so what you send
        replaces it outright. Changing `type` means sending `data` as well, even
        when the value itself stays the same. Either every update is applied or
        none is.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                updates:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                        description: >-
                          The variable's current name, which is also its
                          developer ID
                      newName:
                        type: string
                        pattern: ^[A-Za-z0-9_]+$
                        description: >-
                          A new name for this variable. A variable's name is its
                          developer ID, so renaming it changes how it's
                          referenced: every {{placeholder}} using it is
                          rewritten to match. If not provided, the name remains
                          unchanged.
                      type:
                        type: string
                        enum:
                          - string
                          - number
                          - hyperlink
                          - list
                          - map
                        description: >-
                          A new type for this variable. Must be sent together
                          with `data`, even when the value itself stays the
                          same. If not provided, the type remains unchanged.
                      data:
                        anyOf:
                          - type: object
                            properties:
                              example:
                                anyOf:
                                  - type: number
                                  - type: string
                              fallback:
                                anyOf:
                                  - type: number
                                  - type: string
                            required:
                              - example
                          - type: object
                            properties:
                              example:
                                type: string
                              fallback:
                                type: string
                            required:
                              - example
                          - type: object
                            properties:
                              text:
                                type: string
                              url:
                                type: string
                            required:
                              - text
                              - url
                          - type: array
                            items:
                              type: string
                          - type: object
                            additionalProperties:
                              type: string
                        description: >-
                          The variable's new value. String and number variables
                          have `example` and an optional `fallback`, and
                          hyperlink variables have `text` and `URL`; those
                          fields are fixed, so sending only some of them leaves
                          the rest as they were — send an empty string to clear
                          one. A list variable's value is an array of strings,
                          and a map variable's is an object of string keys to
                          string values; that value is the variable's entire
                          content, so what you send replaces it outright. If not
                          provided, the value remains unchanged.
                    required:
                      - name
                  minItems: 1
                  description: Array of updates to variables
              required:
                - updates
              example:
                updates:
                  - name: user_name
                    newName: customer_name
                  - name: help_link
                    data:
                      text: Read the docs
                      url: https://dittowords.com/docs
      responses:
        '200':
          description: >-
            Returns the variables that changed, and those already in the
            requested state
          content:
            application/json:
              schema:
                type: object
                properties:
                  updated:
                    type: array
                    items:
                      type: string
                    description: Names of the variables that changed
                  unchanged:
                    type: array
                    items:
                      type: string
                    description: >-
                      Names of the variables that were already in the requested
                      state
                required:
                  - updated
                  - unchanged
                example:
                  updated:
                    - customer_name
                  unchanged:
                    - help_link
        '400':
          description: >-
            Returned when the request body fails validation. Common causes
            include: a name that isn't unique in the workspace, a name repeated
            within the request, or data that doesn't match the variable's type.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '404':
          description: Returned when a name doesn't match any variable in the workspace.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
              example:
                message: 'Variable name not found: user_name'
      security:
        - ApiKeyAuth: []
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

````