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

# Get harvest production sessions with per-worker breakdown

> Retrieves production sessions within a date range, each enriched with
aggregated production records per worker and per quality.

Requires API token authentication with the `read:production` scope:
`Authorization: Bearer <keyId>.<token>`.

The `companyId` is always taken from the authenticated token. Optional
`projectId` and `sectorId` filters are validated against that token's
company before data is returned.




## OpenAPI

````yaml /openapi.yaml get /api/control/harvest
openapi: 3.0.3
info:
  title: Hydrobit B2B API
  version: 2.0.0
  description: |
    Public B2B API documentation for Harvest and Phytosanitary data.

    All endpoints require a scoped API token sent in the `Authorization` header:
    `Bearer <keyId>.<token>`.

    API access is available for Corporate accounts. For access or support,
    contact support@hydrobit.ag.
  contact:
    name: Hydrobit Support
    url: https://hydrobit.ag
    email: support@hydrobit.ag
  license:
    name: Proprietary
    url: https://www.hydrobit.ag/terms-conditions
servers:
  - url: https://api.hydrobit.ag
    description: Production server
security:
  - apiTokenAuth: []
tags:
  - name: Harvest
    description: >-
      External B2B endpoints for harvest production sessions and per-worker
      breakdowns.
  - name: Phytosanitary
    description: External B2B endpoints for phytosanitary monitoring and analysis.
paths:
  /api/control/harvest:
    get:
      tags:
        - Harvest
      summary: Get harvest production sessions with per-worker breakdown
      description: |
        Retrieves production sessions within a date range, each enriched with
        aggregated production records per worker and per quality.

        Requires API token authentication with the `read:production` scope:
        `Authorization: Bearer <keyId>.<token>`.

        The `companyId` is always taken from the authenticated token. Optional
        `projectId` and `sectorId` filters are validated against that token's
        company before data is returned.
      operationId: getHarvest
      parameters:
        - name: startTime
          in: query
          required: true
          description: Start date in YYYY-MM-DD format.
          schema:
            type: string
            pattern: ^\d{4}-\d{2}-\d{2}$
          example: '2026-06-01'
        - name: endTime
          in: query
          required: true
          description: End date in YYYY-MM-DD format.
          schema:
            type: string
            pattern: ^\d{4}-\d{2}-\d{2}$
          example: '2026-06-15'
        - name: projectId
          in: query
          required: false
          description: Optional project filter. Must belong to the token's company.
          schema:
            type: string
          example: proj_123
        - name: sectorId
          in: query
          required: false
          description: Optional sector filter. Must belong to the token's company.
          schema:
            type: string
          example: sector_001
      responses:
        '200':
          description: Harvest sessions retrieved successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HarvestResponse'
        '400':
          description: Missing or invalid request parameters.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Missing, invalid, inactive, expired, or malformed API token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            Insufficient scope or access denied for requested
            project/sector/company.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: Invalid date range.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - apiTokenAuth: []
components:
  schemas:
    HarvestResponse:
      type: object
      properties:
        status:
          type: string
          enum:
            - success
          example: success
        data:
          type: array
          items:
            type: object
            properties:
              sessionId:
                type: string
                example: 665f1a2b3c4d5e6f7a8b9c0d
              localId:
                type: string
                nullable: true
                example: 62159da9-9a81-4085-bcd1-fff452689abf
              projectId:
                type: string
                example: proj_123
              sectorId:
                type: string
                example: sector_001
              sector_name:
                type: string
                nullable: true
                example: Lote A-1
              crop:
                type: string
                nullable: true
                example: Blueberry
              variety:
                type: string
                nullable: true
                example: Biloxi
              day:
                type: string
                format: date-time
                example: '2026-06-10T00:00:00.000Z'
              openedAt:
                type: string
                format: date-time
                nullable: true
                example: '2026-06-10T14:29:48.675Z'
              closedAt:
                type: string
                format: date-time
                nullable: true
                example: '2026-06-10T21:31:40.718Z'
              createdAt:
                type: string
                format: date-time
                nullable: true
                example: '2026-06-10T14:29:52.134Z'
              status:
                type: string
                enum:
                  - open
                  - closed
                example: closed
              closedBy:
                type: string
                nullable: true
                enum:
                  - user
                  - system
                example: user
              closedReason:
                type: string
                nullable: true
                enum:
                  - manual
                  - midnight_local
                  - max_duration
                example: manual
              timezone:
                type: string
                nullable: true
                example: America/Mexico_City
              unit:
                type: string
                nullable: true
                example: box
              maxDurationHours:
                type: integer
                nullable: true
                example: 16
              harvestUnitId:
                type: string
                nullable: true
                example: harvest_unit_123
              harvestLotCode:
                type: string
                nullable: true
                example: HL-20260610-C299128B
              workerCount:
                type: integer
                nullable: true
                example: 12
              notes:
                type: string
                nullable: true
                example: Initial harvest notes
              finalNotes:
                type: string
                nullable: true
                example: Closed manually after final count
              license_plate:
                type: string
                nullable: true
                example: ABC-123
              driver_name:
                type: string
                nullable: true
                example: Juan Perez
              totalUnits:
                type: number
                example: 320
              needsRecalc:
                type: boolean
                example: false
              qualityBreakdownAt:
                type: string
                format: date-time
                nullable: true
                example: '2026-06-10T21:33:10.284Z'
              responsible:
                type: object
                properties:
                  auth0Id:
                    type: string
                    nullable: true
                    example: auth0|697797d7095fa22599ac90bb
                  name:
                    type: string
                    nullable: true
                    example: Maria Lopez
                  email:
                    type: string
                    nullable: true
                    example: maria@example.com
                  role:
                    type: string
                    nullable: true
                    example: supervisor
                  picture:
                    type: string
                    nullable: true
                    example: https://example.com/avatar.jpg
              qualityBreakdown:
                type: array
                description: >-
                  Session-level quality snapshot from MongoDB; may lag if
                  needsRecalc is true.
                items:
                  type: object
                  properties:
                    qualityId:
                      type: string
                      nullable: true
                      example: Q1
                    qualityName:
                      type: string
                      nullable: true
                      example: Primera
                    units:
                      type: number
                      example: 240
                    percent:
                      type: number
                      example: 75
              workers:
                type: array
                items:
                  type: object
                  properties:
                    workerId:
                      type: string
                      example: W1
                    worker_name:
                      type: string
                      nullable: true
                      example: Juan Perez
                    validUnits:
                      type: number
                      description: Units excluding voided records.
                      example: 120
                    netUnits:
                      type: number
                      description: >-
                        Sum of all units including negative void
                        counter-movements.
                      example: 110
                    recordCount:
                      type: integer
                      example: 42
                    voidedCount:
                      type: integer
                      example: 3
                    qualityBreakdown:
                      type: array
                      items:
                        type: object
                        properties:
                          qualityId:
                            type: string
                            nullable: true
                            example: Q1
                          qualityName:
                            type: string
                            nullable: true
                            example: Primera
                          validUnits:
                            type: number
                            example: 90
                          recordCount:
                            type: integer
                            example: 30
        meta:
          type: object
          properties:
            sessionCount:
              type: integer
              example: 1
            startTime:
              type: string
              example: '2026-06-01'
            endTime:
              type: string
              example: '2026-06-15'
    Error:
      type: object
      properties:
        error:
          type: string
          example: Internal server error
        message:
          type: string
          example: Detailed error message
  securitySchemes:
    apiTokenAuth:
      type: http
      scheme: bearer
      bearerFormat: keyId.token
      description: |
        Scoped API token for external B2B endpoints. Send it in the
        `Authorization` header as `Bearer <keyId>.<token>`.

````