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

# Create or update a contract

> This API manages the lifecycle of a contract for a given siteID.

The contract is applicable starting the ts value of its applicable contract and ends with the next contract beginning

A tariff calendar can be sent along with a contract, Otherwise the default DNO calendar is used.

The tariff calendar is not handled for the gas fluid.




## OpenAPI

````yaml /api-reference/contracts.yaml post /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:
    post:
      tags:
        - contracts
      summary: Create or update a contract
      description: >
        This API manages the lifecycle of a contract for a given siteID.


        The contract is applicable starting the ts value of its applicable
        contract and ends with the next contract beginning


        A tariff calendar can be sent along with a contract, Otherwise the
        default DNO calendar is used.


        The tariff calendar is not handled for the gas fluid.
      operationId: postContracts
      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
      requestBody:
        content: {}
        required: true
        description: "```json json_schema\r\n{\r\n  \"type\": \"object\",\r\n  \"properties\": {\r\n    \"contracts\": {\r\n      \"type\": \"array\",\r\n      \"items\": {\r\n        \"type\": \"object\",\r\n        \"properties\": {\r\n          \"ts\": {\r\n            \"type\": \"string\",\r\n            \"description\": \"Functional start date for the contract\\n\\r This key is used to identify the contract applicable at a given date.\\n\\rThe supported format is as defined by RFC 3339, section 5.6 restricted to : full-date'T'partial-time'Z'\",\r\n            \"example\":\"2021-07-21T22:00:00Z\"\r\n          },\r\n          \"generationTs\": {\r\n            \"type\": \"string\",\r\n            \"description\":\"Date used to historize contracts for a given ts. \\n\\r When there are multiple contracts with the same ts value, the one with the most recent generationTs is used. \\n\\r The supported format is as defined by RFC 3339, section 5.6 restricted to : full-date'T'partial-time'Z'\",\r\n            \"example\": \"2022-05-17T14:28:37Z\"\r\n          },\r\n          \"supplyContractParameters\": {\r\n            \"type\": \"object\",\r\n            \"description\": \"Parameters and values describing the contract. This list may vary depending on Marketer's configuration\",\r\n            \"example\" : \"{ \\\"TARIFF\\\": \\\"ELEC_PE_VERT\\\",\r\n          \\\"TARIFF_OPTION\\\": \\\"HPHC\\\",\r\n          \\\"SUBSCRIBED_POWER\\\": \\\"9\\\",\r\n          \\\"MILLESIME\\\": \\\"2\\\"\r\n                }\"\r\n          },\r\n          \"tariffCalendar\": {\r\n            \"type\": \"array\",\r\n            \"description\": \"Distributor calendar associated to the client's site. Specific to electricity contracts.\",\r\n            \"items\": {\r\n              \"type\":\"object\",\r\n              \"properties\" : {\r\n                \"periods\":{\r\n                  \"type\": \"array\",\r\n                  \"description\": \"Period for which the calendar is defined : \\n\\r - If tariffCalendar contains more than one object, then a period must be defined for each. \\n\\r - Periods defined within tariffCalendar must cover a full year without overlap \\n\\r - The beginDate must precede the endDate \",\r\n                  \"items\": [\r\n                    {\r\n                      \"type\": \"object\",\r\n                      \"properties\": {\r\n                        \"beginDate\": {\r\n                          \"type\": \"string\",\r\n                          \"description\": \"Start date of the period. This date is included.\\n\\r The supported format is as defined by RFC 3339 : --MM:DD\",\r\n                          \"example\": \"--01-01\"\r\n                        },\r\n                        \"endDate\": {\r\n                          \"type\": \"string\",\r\n                          \"description\": \"End date of the period. This date is included.\\n\\r The supported format is as defined by RFC 3339 : --MM:DD\",\r\n                          \"example\": \"--12-31\"\r\n                        }\r\n                      },\r\n                      \"required\": [\r\n                        \"beginDate\",\r\n                        \"endDate\"\r\n                      ]\r\n                    }\r\n                  ]\r\n                },\r\n                \"timeRangeByLabels\": {\r\n                  \"type\": \"array\",\r\n                  \"description\": \"Defines the period of activity for a list of labels\",\r\n                  \"items\": {\r\n                    \"type\": \"object\",\r\n                    \"properties\": {\r\n                      \"label\": {\r\n                        \"type\": \"string\",\r\n                        \"description\": \"Label name (= Dial name). By convention, value is \\\"cadran1\\\" \",\r\n                        \"example\": \"cadran1\",\r\n                      },\r\n                      \"ranges\": {\r\n                        \"type\": \"array\",\r\n                        \"description\": \"Time ranges during which the label is active\",\r\n                        \"items\": {\r\n                          \"type\": \"object\",\r\n                          \"properties\": {\r\n                            \"begin\": {\r\n                              \"type\": \"string\",\r\n                              \"description\": \"Begin time in HH:mm:ss format\",\r\n                              \"example\": \"00:00:00\"\r\n                            },\r\n                            \"end\": {\r\n                              \"type\": \"string\",\r\n                              \"description\": \"End time in HH:mm:ss format\",\r\n                              \"example\": \"06:00:00\"\r\n                            }\r\n                          },\r\n                          \"required\": [\r\n                            \"begin\",\r\n                            \"end\"\r\n                          ]\r\n                        }\r\n                      }\r\n                    },\r\n                    \"required\": [\r\n                      \"label\",\r\n                      \"ranges\"\r\n                    ]\r\n                  }\r\n                }\r\n              },\r\n              \"required\": [\r\n                \"timeRangeByLabels\"\r\n              ]\r\n            }\r\n          }\r\n        },\r\n        \"required\": [\r\n          \"ts\",\r\n          \"generationTs\",\r\n          \"supplyContractParameters\"\r\n        ]\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n"
      responses:
        '204':
          description: OK. No content
          content: {}
        '400':
          description: Functional error.
          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:write home:gas-contracts:write
components:
  schemas:
    ErrorResponse:
      required:
        - errorCode
        - errorDescription
      type: object
      properties:
        errorCode:
          description: The error code.
          type: string
        errorDescription:
          type: string
          description: The error description
      description: ErrorResponse
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````