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

# Update Metric Value

> Updates the latest value for a metric displayed in ActivitySmith widgets. Create the metric in the web app first, then update its value using the key.



## OpenAPI

````yaml POST /metrics/{key}/value
openapi: 3.1.0
info:
  title: ActivitySmith API
  description: >-
    Send push notifications and Live Activities to your own devices via a single
    API key.
  version: 1.0.0
servers:
  - url: https://activitysmith.com/api
security:
  - apiKeyAuth: []
tags:
  - name: PushNotifications
    description: Send push notifications to paired devices.
  - name: AppIconBadges
    description: Update App Icon Badge Counts on paired devices.
  - name: LiveActivities
    description: Start, update, stream, and end Live Activities.
  - name: Metrics
    description: Update metric values shown in ActivitySmith widgets.
paths:
  /metrics/{key}/value:
    post:
      tags:
        - Metrics
      summary: Update a widget metric value
      description: >-
        Updates the latest value for a metric displayed in ActivitySmith
        widgets. Create the metric in the web app first, then update its value
        using the key.
      operationId: updateMetricValue
      parameters:
        - name: key
          in: path
          required: true
          description: >-
            Metric key configured in the web app. Lowercase letters, numbers,
            dots, underscores, and dashes are allowed.
          schema:
            type: string
            minLength: 1
            maxLength: 64
            pattern: ^[a-z0-9][a-z0-9_.-]{0,63}$
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MetricValueUpdateRequest'
            example:
              value: 42
      responses:
        '200':
          description: Metric value updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricValueUpdateResponse'
              examples:
                success:
                  value:
                    success: true
        '400':
          description: Bad request (invalid key or value)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricError'
              examples:
                invalid_value:
                  value:
                    error: value must be a finite number
        '404':
          description: Metric not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricError'
              examples:
                not_found:
                  value:
                    error: Metric not found
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitError'
              examples:
                rate_limited:
                  value:
                    error: Rate limit exceeded
                    message: Too many requests, please try again later.
      x-codeSamples:
        - lang: javascript
          label: Node
          source: |-
            import ActivitySmith from "activitysmith";

            const activitysmith = new ActivitySmith({
              apiKey: process.env.ACTIVITYSMITH_API_KEY,
            });

            await activitysmith.metrics.update("deploy.success_rate", 99.9);
        - lang: python
          label: Python
          source: >-
            import os

            from activitysmith import ActivitySmith


            activitysmith =
            ActivitySmith(api_key=os.environ["ACTIVITYSMITH_API_KEY"])


            activitysmith.metrics.update("deploy.success_rate", 99.9)
        - lang: go
          label: Go
          source: "package main\n\nimport (\n\t\"log\"\n\n\tactivitysmithsdk \"github.com/ActivitySmithHQ/activitysmith-go\"\n)\n\nfunc main() {\n\tactivitysmith, err := activitysmithsdk.New(\"YOUR-API-KEY\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t_, err = activitysmith.Metrics.Update(\"deploy.success_rate\", 99.9)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n}"
        - lang: php
          label: PHP
          source: |-
            <?php

            use ActivitySmith\ActivitySmith;

            $activitysmith = new ActivitySmith($_ENV['ACTIVITYSMITH_API_KEY']);

            $activitysmith->metrics->update('deploy.success_rate', 99.9);
        - lang: ruby
          label: Ruby
          source: >-
            require "activitysmith"


            activitysmith = ActivitySmith::Client.new(api_key:
            ENV.fetch("ACTIVITYSMITH_API_KEY"))


            activitysmith.metrics.update("deploy.success_rate", 99.9)
        - lang: bash
          label: cURL
          source: >-
            curl -X POST
            "https://activitysmith.com/api/metrics/deploy.success_rate/value" \
              -H "Authorization: Bearer $ACTIVITYSMITH_API_KEY" \
              -H "Content-Type: application/json" \
              -d '{ "value": 99.9 }'
components:
  schemas:
    MetricValueUpdateRequest:
      type: object
      description: Latest metric value to display in widgets.
      properties:
        value:
          oneOf:
            - type: number
            - type: string
              minLength: 1
              maxLength: 64
        timestamp:
          type: string
          format: date-time
          description: >-
            Optional ISO timestamp for when the metric value was measured.
            Defaults to the server receive time.
      required:
        - value
      additionalProperties: false
    MetricValueUpdateResponse:
      type: object
      properties:
        success:
          type: boolean
      required:
        - success
      additionalProperties: false
    MetricError:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
      required:
        - error
      additionalProperties: true
    RateLimitError:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
      required:
        - error
        - message
      additionalProperties: false
  securitySchemes:
    apiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Required. Include `Authorization: Bearer ask_123456789` in every
        request. Replace `ask_123456789` with your API key.

````