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

# Get contracts for a SiteId

> Returns the contracts applicable between two dates for a given type of fluid.

If several contracts with a ts on the same day exists for this site, only one contract will be returned: the one with the most recent ts and generationTs. Only this contract will be considered for the consumption calculation




## OpenAPI

````yaml /api-reference/contracts.yaml get /sites/{site-id}/contracts
openapi: 3.0.3
info:
  title: Contracts lifecycle
  description: >
    This API manages the lifecycle of contracts associated to a PoD.


    Contract key concepts:

    - A contract is applicable starting it ts value and ends with the next
    contract beginning

    - The definition of an existing contract can be updated using the ts and
    generationTs fields
  termsOfService: TODO
  contact:
    email: api@datanumia.com
  version: 2.0.0
servers:
  - url: https://api.home.datanumia.com/api/v2
    description: Production Server
security: []
paths:
  /sites/{site-id}/contracts:
    get:
      tags:
        - contracts
      summary: Get contracts for a SiteId
      description: >
        Returns the contracts applicable between two dates for a given type of
        fluid.


        If several contracts with a ts on the same day exists for this site,
        only one contract will be returned: the one with the most recent ts and
        generationTs. Only this contract will be considered for the consumption
        calculation
      operationId: getContractWithTariffCalendarsBySiteId
      parameters:
        - name: site-id
          in: path
          required: true
          description: Site identifier provided by Datanumia
          schema:
            type: string
        - name: fluid
          in: query
          description: |
            Type of energy covered by the contract: electricity or gas.
          required: true
          schema:
            type: string
            enum:
              - elec
              - gas
        - name: beginTs
          in: query
          description: >
            Start timestamp for the requested period.


            The supported format is as defined by RFC 3339, section 5.6
            restricted to : full-date'T'partial-time'Z'.


            Default :  customer history limit
          required: false
          example: '2020-07-21T22:00:00Z'
          schema:
            type: string
            format: date-time
        - name: endTs
          in: query
          description: >
            End timestamp for the requested.


            The supported format is as defined by RFC 3339, section 5.6
            restricted to : full-date'T'partial-time'Z'.


            Default : now.
          required: false
          example: '2017-07-21T22:00:00Z'
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: OK - Returns the requested list of contracts for the site-id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetContracts'
        '400':
          description: "Functional error. Possible values:\r\n\r\nERROR CODE | ERROR CASE\r\n-----------|-----------\r\nMISSING_FLUID | Fluid is missing\r\nINVALID_FLUID | Fluid is invalid, it must be either \"elec\" or \"gas\"\r\nINCONSISTENT_SITEID_FLUID | SiteId and fluid are inconsistent\r\nINVALID_TS | BeginTs or EndTs is invalid, it must be in the following format: full-date'T'partial-time'Z'\r\nINVALID_TS | BeginTs cannot be after endTs\r\n\r\nThis list can be expanded over time."
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden
          content: {}
        '404':
          description: Not Found
          content: {}
        '500':
          description: Server error
          content: {}
      security:
        - Bearer:
            - home:elec-contracts:read home:gas-contracts:read
components:
  schemas:
    GetContracts:
      type: object
      properties:
        contracts:
          type: array
          items:
            $ref: '#/components/schemas/ContractDto'
    ErrorResponse:
      required:
        - errorCode
        - errorDescription
      type: object
      properties:
        errorCode:
          description: The error code.
          type: string
        errorDescription:
          type: string
          description: The error description
      description: ErrorResponse
    ContractDto:
      type: object
      required:
        - ts
        - generationTs
        - supplyContractParameters
      properties:
        ts:
          description: >
            Functional start date for the contract.


            This key is used to identify the contract applicable at a given
            date.


            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'
        generationTs:
          description: >
            Date used to historize contract content at a given ts.


            When there are multiple contracts with the same ts value, the one
            with the most recent generationTs is used.


            The supported format is as defined by RFC 3339, section 5.6
            restricted to : full-date'T'partial-time'Z'
          example: '2022-05-17T14:28:37Z'
          type: string
          format: date-time
        supplyContractParameters:
          type: object
          example:
            TARIFF: ELEC_PE_VERT
            TARIFF_OPTION: HPHC
            SUBSCRIBED_POWER: '9'
            MILLESIME: '2'
          description: >-
            Parameters and values describing the contract. This list may vary
            depending on Marketer's configuration
          additionalProperties:
            type: string
        tariffCalendar:
          type: array
          items:
            $ref: '#/components/schemas/TariffCalendar'
    TariffCalendar:
      type: object
      x-examples:
        Example 1:
          periods:
            - beginDate: '--04-01'
              endDate: '--10-31'
          timeRangeByLabels:
            - label: cadran1
              ranges:
                - begin: '00:00:00'
                  end: '06:00:00'
                - begin: '22:00:00'
                  end: '00:00:00'
      required:
        - timeRangeByLabels
      properties:
        periods:
          type: array
          description: "Period for which the calendar is defined :\r\n\r\n- If tariffCalendar contains more than one object, then a period must be defined for each.\r\n- Periods defined within tariffCalendar must cover a full year without overlap\r\n- The beginDate must precede the endDate"
          items:
            type: object
            required:
              - beginDate
              - endDate
            properties:
              beginDate:
                type: string
                description: "Start date of the period. This date is included.\r\n\r\nThe supported format is as defined by RFC 3339 : --MM:DD"
                example: '--01-01'
              endDate:
                type: string
                description: "End date of the period. This date is included.\r\n\r\nThe supported format is as defined by RFC 3339 : --MM:DD"
                example: '--12-31'
        timeRangeByLabels:
          type: array
          description: Defines the period of activity for a list of labels
          items:
            type: object
            required:
              - label
              - ranges
            properties:
              label:
                type: string
                description: Label name (= Dial name). By convention, value is "cadran1"
              ranges:
                type: array
                description: Time ranges during which the label is active
                items:
                  type: object
                  required:
                    - begin
                    - end
                  properties:
                    begin:
                      type: string
                      description: Begin time in HH:mm:ss format
                      example: '00:00:00'
                    end:
                      type: string
                      description: End time in HH:mm:ss format
                      example: '06:00:00'
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````