> ## 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.

# Creates a target for a site

> 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 (EURO) or a consumption in kWh (KWH).
Only ELEC is supported as a fluid type.




## OpenAPI

````yaml /api-reference/targets.yaml post /v2/sites/{siteId}/targets
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:
    post:
      tags:
        - targets
      summary: Creates a target for a site
      description: >
        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 (EURO) or a consumption in kWh
        (KWH).

        Only ELEC is supported as a fluid type.
      operationId: postTarget
      parameters:
        - name: siteId
          in: path
          description: site identifier.
          required: true
          schema:
            type: string
          example: d8a9b286-d7c0-493c-9610-403747687023_01
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TargetPostDTO'
        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

            - "FUNCTIONAL_EXCEPTION : BeginDate and endDate are not valid" when
            the begin date is equal to or more recent than the end date

            - "FUNCTIONAL_EXCEPTION : BeginDate is too old (ttl check)" when the
            begin date is older than now - duration of the ttl

            - "FUNCTIONAL_EXCEPTION : BeginDate and endDate overlap with
            other(s) target(s)" when there's already another target on the
            period

            - "FUNCTIONAL_EXCEPTION : StandingCharges is null" when no standing
            charges are found for the period

            - "FUNCTIONAL_EXCEPTION : Invalid number of months for
            standingCharges" when more or less than 12 months of standing
            charges are found

            - "FUNCTIONAL_EXCEPTION : statisticWeightsDto or WeightsByPeriodDto
            is null" when wheights not found

            - "FUNCTIONAL_EXCEPTION : Invalid number of months for
            statisticWeights" when more or less than 12 months of statistic
            weights are 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:
    TargetPostDTO:
      type: object
      required:
        - beginDate
        - endDate
        - type
        - unit
        - targetValue
        - defaultTargetValue
        - notificationType
      properties:
        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
          example: NONE
        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

````