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

# Update Rule

> Update a rule. The segment and variants referred to by the rule must exist.



## OpenAPI

````yaml /api/flags/api/flag.openapi.json patch /v1/flags/{flag}/rules/{rule}
openapi: 3.1.0
info:
  title: Confidence Flag API
  version: 1.0.0
  description: API documentation for flag
servers: []
security: []
paths:
  /v1/flags/{flag}/rules/{rule}:
    patch:
      summary: Update Rule
      description: >-
        Update a rule. The segment and variants referred to by the rule must
        exist.
      operationId: Rule.update
      parameters:
        - name: flag
          in: path
          required: true
          schema:
            type: string
        - name: rule
          in: path
          required: true
          schema:
            type: string
        - name: updateMask
          in: query
          required: false
          description: >-
            The list of fields in the Rule that you want to update e.g.
            'segment',
             if empty all mutable properties are updated.
             Fields are specified relative to the rule.
          schema:
            type: object
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: |-
                    The resource name of the rule.
                     For example:
                     `flags/my-flag/rules/1bhq4c2zqigdzqg6ufni`
                description:
                  type: string
                  description: A description for the rule.
                segment:
                  type: string
                  description: >-
                    A reference to the segment that this rule uses to specify
                    entities
                     that are eligible.
                assignmentSpec:
                  type: object
                  properties:
                    bucketCount:
                      type: object
                      description: >-
                        The total number of buckets to consider when
                        randomizing.
                    assignments:
                      type: array
                      items:
                        type: object
                        properties:
                          assignmentId:
                            type: string
                            description: Opaque identifier of this assignment.
                          variant:
                            type: object
                            properties:
                              variant:
                                type: string
                                description: >-
                                  Reference to a variant in the flag. Note: the
                                  variant must be located
                                   in the same flag.
                            required:
                              - variant
                            description: Assign a value from a variant.
                          fallthrough:
                            type: object
                            description: >-
                              Assign a value from the first rule after this one
                              that matches.
                          clientDefault:
                            type: object
                            description: Assign the default values in the client.
                          bucketRanges:
                            type: array
                            items:
                              type: object
                              properties:
                                lower:
                                  type: object
                                  description: The start bucket (inclusive).
                                upper:
                                  type: object
                                  description: The end bucket (exclusive).
                              required:
                                - lower
                                - upper
                            description: The range of buckets that the variant occupies.
                      description: A list that divides the total buckets into assignments
                  description: >-
                    Specification of how an entity should be randomly assigned
                    to values.
                targetingKeySelector:
                  type: string
                  description: >-
                    Selector of what key to randomize on from the evaluation
                    context.
                     "targeting_key" is the default if not specified
                enabled:
                  type: boolean
                  description: Decides if the rule should be enabled for resolve or not.
                environments:
                  type: array
                  items:
                    type: string
                  description: >-
                    List of environments this rule is enabled for. If this list
                    is empty, the rule
                     is enabled for all environments.
                labels:
                  type: array
                  items:
                    type: object
                    additionalProperties:
                      type: string
                  description: General set of labels for this resource.
                materializationSpec:
                  type: object
                  properties:
                    writeMaterialization:
                      type: string
                      description: Feeds assignments into materialization
                    readMaterialization:
                      type: string
                      description: Reads assignments from materialization
                    mode:
                      type: object
                      properties:
                        materializationMustMatch:
                          type: boolean
                          description: >-
                            If the materialization must match, only units in the
                            materialization will be in the rule, all other units
                             will skip this rule (also known as paused intake). If this is set to false units will match if they are in
                             the materialization or if they match the segment.
                        segmentTargetingCanBeIgnored:
                          type: boolean
                          description: >-
                            By default materialization will only be seen as a
                            match of the targeting of the segment that the rule
                             references also matches. Depending on the type of targeting, this may or may not be the wanted behaviour.
                             Setting this to true will mean that any unit in the materialization will match the rule no matter if
                             they match the targeting. Irrespective if this is set to false or true the segment allocation
                             proportion/bucketing is ignored for any unit in the materialization.
                      description: How materialization reads should be treated
                  description: Specifies if materializations are written to/read from
              required:
                - segment
                - assignmentSpec
                - enabled
        required: true
      responses:
        '200':
          description: Returns a [Flag.Rule](/api-reference/schemas/flag-rule).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/confidence.flags.admin.v1.Flag.Rule'
      security:
        - admin: []
      servers:
        - url: https://flags.eu.confidence.dev
        - url: https://flags.us.confidence.dev
        - url: https://flags.confidence.dev
components:
  schemas:
    confidence.flags.admin.v1.Flag.Rule:
      title: Flag.Rule
      type: object
      description: A rule that decides how a subset of the flags variants are assigned.
      properties:
        name:
          type: string
          description: |-
            The resource name of the rule.
             For example:
             `flags/my-flag/rules/1bhq4c2zqigdzqg6ufni`
        description:
          type: string
          description: A description for the rule.
        segment:
          type: string
          description: |-
            A reference to the segment that this rule uses to specify entities
             that are eligible.
        assignmentSpec:
          type: object
          properties:
            bucketCount:
              type: object
              description: The total number of buckets to consider when randomizing.
            assignments:
              type: array
              items:
                type: object
                properties:
                  assignmentId:
                    type: string
                    description: Opaque identifier of this assignment.
                  variant:
                    type: object
                    properties:
                      variant:
                        type: string
                        description: >-
                          Reference to a variant in the flag. Note: the variant
                          must be located
                           in the same flag.
                    required:
                      - variant
                    description: Assign a value from a variant.
                  fallthrough:
                    type: object
                    description: >-
                      Assign a value from the first rule after this one that
                      matches.
                  clientDefault:
                    type: object
                    description: Assign the default values in the client.
                  bucketRanges:
                    type: array
                    items:
                      type: object
                      properties:
                        lower:
                          type: object
                          description: The start bucket (inclusive).
                        upper:
                          type: object
                          description: The end bucket (exclusive).
                      required:
                        - lower
                        - upper
                    description: The range of buckets that the variant occupies.
              description: A list that divides the total buckets into assignments
          description: >-
            Specification of how an entity should be randomly assigned to
            values.
        usageMetadata:
          type: object
          properties:
            resolveCount:
              type: integer
              description: The total number of resolves of this rule.
            applyCount:
              type: integer
              description: Total number of applies to this rule.
            lastResolveTime:
              type: object
              description: The last time this rule was resolved.
            lastApplyTime:
              type: object
              description: The last time this rule was applied.
            assignmentUsageMetadata:
              type: array
              items:
                type: object
                properties:
                  assignmentId:
                    type: string
                    description: >-
                      The assignment id, empty means no assignment id was
                      passed.
                  resolveCount:
                    type: integer
                    description: Total number of resolves.
                  applyCount:
                    type: integer
                    description: Total number of applies.
                  lastApplyTime:
                    type: object
                    description: The last time this rule was applied.
                  emptyTargetingKeyCount:
                    type: integer
                    description: Total number of applies with empty targeting key.
              description: Usage statistics for each assignment.
          description: Metadata about how the flag has been resolved.
        targetingKeySelector:
          type: string
          description: |-
            Selector of what key to randomize on from the evaluation context.
             "targeting_key" is the default if not specified
        enabled:
          type: boolean
          description: Decides if the rule should be enabled for resolve or not.
        environments:
          type: array
          items:
            type: string
          description: >-
            List of environments this rule is enabled for. If this list is
            empty, the rule
             is enabled for all environments.
        createTime:
          type: object
          description: Time when the rule was first created.
        updateTime:
          type: object
          description: Time when the flag was last updated.
        creator:
          type: string
          description: Reference to the identity that created this rule.
        updater:
          type: string
          description: Reference to the identity that last updated this rule.
        labels:
          type: array
          items:
            type: object
            additionalProperties:
              type: string
          description: General set of labels for this resource.
        materializationSpec:
          type: object
          properties:
            writeMaterialization:
              type: string
              description: Feeds assignments into materialization
            readMaterialization:
              type: string
              description: Reads assignments from materialization
            mode:
              type: object
              properties:
                materializationMustMatch:
                  type: boolean
                  description: >-
                    If the materialization must match, only units in the
                    materialization will be in the rule, all other units
                     will skip this rule (also known as paused intake). If this is set to false units will match if they are in
                     the materialization or if they match the segment.
                segmentTargetingCanBeIgnored:
                  type: boolean
                  description: >-
                    By default materialization will only be seen as a match of
                    the targeting of the segment that the rule
                     references also matches. Depending on the type of targeting, this may or may not be the wanted behaviour.
                     Setting this to true will mean that any unit in the materialization will match the rule no matter if
                     they match the targeting. Irrespective if this is set to false or true the segment allocation
                     proportion/bucketing is ignored for any unit in the materialization.
              description: How materialization reads should be treated
          description: Specifies if materializations are written to/read from
      required:
        - segment
        - assignmentSpec
        - usageMetadata
        - enabled
        - createTime
        - updateTime
        - creator
        - updater
  securitySchemes:
    admin:
      type: http
      scheme: bearer

````