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

# Updates a target for a given site

> Updates an existing target.
Only targetValue, notificationChannels and notificationType can be updated. Any attempt to do otherwise will generate a functional error.




## OpenAPI

````yaml /api-reference/targets.yaml put /v2/sites/{siteId}/targets/{targetId}
openapi: 3.0.3
info:
  title: Targets lifecycle
  description: >
    Target key concepts:

    - A target is applicable for 12 months and spans from the start of the year
    to its end.

    - A target can either be a cost in euros or a consumption in kWh. The value
    of the target can be updated but not its unit type.
  termsOfService: TODO
  contact:
    email: api@datanumia.com
  version: 2.0.0
servers:
  - url: https://api.home.datanumia.com/api
    description: Production Server
security: []
paths:
  /v2/sites/{siteId}/targets/{targetId}:
    put:
      tags:
        - targets
      summary: Updates a target for a given site
      description: >
        Updates an existing target.

        Only targetValue, notificationChannels and notificationType can be
        updated. Any attempt to do otherwise will generate a functional error.
      operationId: putTarget
      parameters:
        - name: siteId
          in: path
          description: site identifier.
          required: true
          schema:
            type: string
          example: d8a9b286-d7c0-493c-9610-403747687023_01
        - name: targetId
          in: path
          description: target identifier.
          required: true
          schema:
            type: string
          example: 2FD7EADA83E24121C5EC0CFCBBEBCF819E08BDD845163E1C9D451737CC12BCFC
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TargetPutDTO'
        required: true
      responses:
        '204':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResponseOK'
        '400':
          description: >
            Functional Error.

            Error cases:

            - SITE_NOT_FOUND when the site referenced in the path doesn't exist

            - TARGET_ID_MANDATORY when no target id is given

            - "FUNCTIONAL_EXCEPTION : Target not found"

            - "FUNCTIONAL_EXCEPTION : Path and body targetId mismatch"

            - "FUNCTIONAL_EXCEPTION : Attempting to edit unauthorized target
            attribute: only targetValue, notificationChannels and/or
            notificationType can be modify"

            - "FUNCTIONAL_EXCEPTION : TargetAlert not found"

            - Aside from the specific cases mentioned before, db errors are
            caught and rethrown as this
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                errorCode: SITE_NOT_FOUND
                errorDescription: Unknown site
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseUnauthorized'
        '403':
          description: Forbidden
          content: {}
        '404':
          description: Not Found
          content: {}
        '500':
          description: Server error
          content: {}
      security:
        - Bearer:
            - home:consumption-targets:targets:write
components:
  schemas:
    TargetPutDTO:
      type: object
      required:
        - targetId
        - generationTs
        - beginDate
        - endDate
        - type
        - unit
        - targetValue
        - defaultTargetValue
        - notificationType
      properties:
        siteId:
          description: Site id
          type: string
          example: d8a9b286-d7c0-493c-9610-403747687023_01
        targetId:
          description: Target id
          type: string
          example: 2FD7EADA83E24121C5EC0CFCBBEBCF819E08BDD845163E1C9D451737CC12BCFC
        generationTs:
          description: >
            The timestamp at which the target was generated

            The supported format is as defined by RFC 3339, section 5.6
            restricted to : full-date'T'partial-time'Z'
          type: string
          format: date-time
          example: '2021-07-21T22:00:00Z'
        beginDate:
          description: >
            The timestamp at which the target period starts

            The supported format is as defined by RFC 3339, section 5.6
            restricted to : full-date'T'partial-time'Z'
          type: string
          format: date-time
          example: '2021-12-31T23:00:00Z'
        endDate:
          description: >
            The timestamp at which the target period ends

            The supported format is as defined by RFC 3339, section 5.6
            restricted to : full-date'T'partial-time'Z'
          type: string
          format: date-time
          example: '2022-12-31T23:00:00Z'
        type:
          description: The fluid type for the target (only ELEC is properly supported)
          type: string
          enum:
            - ELEC
          example: ELEC
        unit:
          description: >
            The designated unit type for the target, which can be either EURO or
            KWH
          type: string
          enum:
            - EURO
            - KWH
          example: EURO
        targetValue:
          description: |
            "The yearly value for the target"
          type: integer
          example: 3000
        defaultTargetValue:
          description: >
            "The yearly default value for the target; the reference value based
            on similar homes or past consumptions"
          type: integer
          example: 3100
        notificationChannels:
          description: |
            The channels used to send notifications (EMAIL, SMS, both or none)
          type: array
          items:
            type: string
          example: []
        notificationType:
          description: >
            The condition that defines whether a notification should be sent or
            not
          type: string
          enum:
            - NONE
            - ON_DIST_INDEX_RECEPTION
            - THRESHOLD_OVERRUN
        name:
          description: |
            The target's name
          type: string
          example: My target
    ResponseOK:
      type: object
      properties:
        targetId:
          description: The target id for the processed target
          type: string
          example: 17636C2876EFA9B8A4A8B061043952895C51A129DB22ED73F835C2FC3F79E9B2
    ErrorResponse:
      required:
        - errorCode
        - errorDescription
      type: object
      properties:
        errorCode:
          description: The error code.
          type: string
          example: SITE_NOT_FOUND
        errorDescription:
          type: string
          description: The error description
          example: Unknown site
      description: ErrorResponse
    ErrorResponseUnauthorized:
      required:
        - errorCode
        - errorDescription
      type: object
      properties:
        errorCode:
          description: The error code.
          type: string
          example: INVALID_AUTHORIZATION_HEADER_VALUE
        errorDescription:
          type: string
          description: The error description
          example: The Authorization header is invalid
      description: ErrorResponse
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````