> ## Documentation Index
> Fetch the complete documentation index at: https://botpress-ak-docs-20-document-updating-variables-from-outsid.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# getOrSetState

> Retrieves the [State](#schema_state) object for a valid identifiers. If the state does not exist, it creates a new state.



## OpenAPI

````yaml runtime-openapi.json post /v1/chat/states/{type}/{id}/{name}/get-or-set
openapi: 3.0.0
info:
  title: Botpress Runtime API
  description: API for Botpress Runtime
  version: 1.52.1
servers:
  - url: https://api.botpress.cloud
security:
  - BearerAuth: []
tags:
  - name: documented
paths:
  /v1/chat/states/{type}/{id}/{name}/get-or-set:
    post:
      tags:
        - Endpoints
      description: >-
        Retrieves the [State](#schema_state) object for a valid identifiers. If
        the state does not exist, it creates a new state.
      operationId: getOrSetState
      parameters:
        - name: type
          in: path
          description: Represents the resource type that the state is related to
          required: true
          schema:
            type: string
            enum:
              - conversation
              - user
              - bot
              - integration
              - task
              - workflow
        - name: id
          in: path
          description: >-
            Id of the State which will be either the botId, the userId or the
            conversationId
          required: true
          schema:
            type: string
        - name: name
          in: path
          description: Name of the State which is declared inside the bot definition
          required: true
          schema:
            type: string
        - name: x-bot-id
          in: header
          description: Bot id
          required: true
          schema:
            type: string
        - name: x-integration-id
          in: header
          description: Integration id
          required: false
          schema:
            type: string
        - name: x-integration-alias
          in: header
          description: Integration alias
          required: false
          schema:
            type: string
      requestBody:
        $ref: '#/components/requestBodies/getOrSetStateBody'
      responses:
        '200':
          $ref: '#/components/responses/getOrSetStateResponse'
        default:
          $ref: '#/components/responses/getOrSetStateResponse'
components:
  requestBodies:
    getOrSetStateBody:
      description: State content
      content:
        application/json:
          schema:
            type: object
            properties:
              payload:
                type: object
                additionalProperties: true
                description: Payload is the content of the state defined by your bot.
              expiry:
                type: number
                minimum: 1
                maximum: 2592000000
                nullable: true
                description: >-
                  Expiry of the [State](#schema_state) in milliseconds. The
                  state will expire if it is idle for the configured value. By
                  default, a state doesn't expire.
            required:
              - payload
            title: getOrSetStateBody
            additionalProperties: false
  responses:
    getOrSetStateResponse:
      description: >-
        Returns the [State](#schema_state) object if a valid identifiers were
        provided. Returns [an error](#errors) otherwise.
      content:
        application/json:
          schema:
            type: object
            properties:
              state:
                $ref: '#/components/schemas/State'
              meta:
                type: object
                properties:
                  cached:
                    type: boolean
                required:
                  - cached
                additionalProperties: false
            required:
              - state
              - meta
            title: getOrSetStateResponse
            additionalProperties: false
  schemas:
    State:
      type: object
      properties:
        id:
          type: string
          minLength: 28
          maxLength: 36
          description: Id of the [State](#schema_state)
        createdAt:
          type: string
          format: date-time
          description: Creation date of the [State](#schema_state) in ISO 8601 format
        updatedAt:
          type: string
          format: date-time
          description: Updating date of the [State](#schema_state) in ISO 8601 format
        botId:
          type: string
          minLength: 28
          maxLength: 36
          description: Id of the [Bot](#schema_bot)
        conversationId:
          type: string
          minLength: 28
          maxLength: 36
          description: Id of the [Conversation](#schema_conversation)
        userId:
          type: string
          minLength: 28
          maxLength: 36
          description: Id of the [User](#schema_user)
        name:
          type: string
          maxLength: 200
          description: >-
            Name of the [State](#schema_state) which is declared inside the bot
            definition
        type:
          type: string
          enum:
            - conversation
            - user
            - bot
            - task
            - integration
            - workflow
          description: >-
            Type of the [State](#schema_state) represents the resource type
            (`conversation`, `user`, `bot`, `task`, `integration` or `workflow`)
            that the state is related to
        payload:
          type: object
          additionalProperties: true
          description: Payload is the content of the state defined by your bot.
      required:
        - id
        - createdAt
        - updatedAt
        - botId
        - name
        - type
        - payload
      description: >-
        The state object represents the current payload. A state is always
        linked to either a bot, a conversation or a user.
      additionalProperties: false
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````