APIs & services / portfolio-service

Record an ATM harvest.

Endpointtoday's app
Call
POST /gateway/portfolio-service/api/v1/farming-model/harvest/{entityId}/{entityType}
Service
portfolio-service
Features
ATM harvest
When
User saves ATM harvest (queued directly, no ledger)
Auth
X-SESSIONID stamped when queued (CoreAPI dooWithRetry); X-REQUESTID idempotency key
In the App Service

Use case

Queued directly from AtmHarvestViewModel.postFarmingModelHarvest when the user saves an ATM harvest (no sync ledger entry). Harvest rows are first stored in farming_model_harvest and the farming model line items are marked PENDING (continuous) or COMPLETED (whole crop). FarmingModelHarvestPostRH does nothing on success; failures retry from the queue (and appear in Pending Sync as 'Add ATM harvest log').

Headers

HeaderValueNotes
X-SESSIONID<session token>Stamped when the operation is queued (dooWithRetry) and re-set by CoreAPI at send time; refreshed on 401.
X-REQUESTID<uuid v4>Idempotency key generated by OperationManagerImpl.createOperation for POST/PUT/PATCH when the op enters the offline queue.
X-ACK-REQUESTID<X-REQUESTID of an earlier completed op>Added by SyncQueueProcessor for POST/PUT/PATCH: acknowledges a request id the device already saw succeed.
Content-Typeapplication/jsonAdded by CoreAPI.

Parameters

ParamInRequiredExampleNotes
entityIdpathYes40001Farmer IE id.
entityTypepathYesENTITY_TYPE.IEOwner type.

Request

Example request body (synthetic data)
[
  {
    "id": null,
    "genericProduct": "PRODUCT.SPINACH",
    "cropType": "CROP_TYPE.VEGETABLE",
    "cropSubType": "CROP_SUB_TYPE.LEAFY",
    "harvestDate": "2026-09-01",
    "remarks": null,
    "harvestGeoTag": "17.0000,78.0000",
    "harvestCompleteDate": "2026-09-01",
    "harvestStatus": "HARVEST_STATUS.COMPLETED",
    "farmingModelId": 5501,
    "farmingModelLineItemId": 5601,
    "expectedOutput": {
      "id": null,
      "uoM": {
        "code": "UOM.KG",
        "symbol": "kg",
        "name": "Kilogram",
        "description": "Kilogram",
        "measurementType": {
          "code": "MEASUREMENT_TYPE.WEIGHT",
          "globalRefClass": {
            "code": "GREF.MEASUREMENT_TYPE",
            "name": "Measurement type",
            "description": ""
          },
          "name": "Weight",
          "description": ""
        }
      },
      "value": 20
    },
    "actualOutput": {
      "id": null,
      "uoM": {
        "code": "UOM.KG",
        "symbol": "kg",
        "name": "Kilogram"
      },
      "value": 18
    },
    "surplusOutput": {
      "id": null,
      "uoM": {
        "code": "UOM.KG",
        "symbol": "kg",
        "name": "Kilogram"
      },
      "value": 5
    },
    "harvestType": "HARVEST_TYPE.WHOLE_CROP",
    "isMajorCrop": false,
    "expectedHarvestDate": "2026-09-01",
    "earlyHarvestReason": null,
    "interestedInCropMarketing": true,
    "cropChangeReason": null
  }
]
FieldTypeRequiredNotes
[].farmingModelId / farmingModelLineItemIdintegerYesATM and crop being harvested.
[].genericProduct / cropType / cropSubType / isMajorCropmixedYesCrop.
[].harvestDate / harvestCompleteDate / expectedHarvestDatestringYesDates from the ATM harvest form.
[].harvestType / harvestStatusstringYesCONTINOUS vs WHOLE_CROP; PENDING/COMPLETED.
[].expectedOutput / actualOutput / surplusOutputobjectNoQuantity + UoM.
[].earlyHarvestReason, interestedInCropMarketing, remarks, harvestGeoTag, cropChangeReasonmixedNoForm answers.
[].idintegerNoLocal autoincrement id (sent but meaningless to server).

Response

FieldTypeRequiredNotes
(body)unknownNot read by the app.

Errors

StatusWhenWhat the app does
401Session token expired or invalidCoreAPI invalidates the session id and retries once immediately; if still failing the op stays in the queue (TryAgain.LATER).
500Server error on a /gateway URLBaseResponseHandler fetches a new session id (first 5 attempts) and returns TryAgain.LATER; retried per RetryScheduler policy (retry threshold/delay come from app config).
503Service unavailableCoreAPI retries once immediately, then the op is retried later by the sync queue.
any non-2xxAny other failureHandler onError -> TryAgain.LATER (op stays queued and is visible in Pending Sync); a row is written to the local error_log table (Sync Error Log screen) with URL, body, headers and raw response; every 10th attempt the op is mirrored to Firestore for support.

Source

  • app/src/main/java/org/platformcommons/urvi/view/atm/harvest/AtmHarvestViewModel.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/entity/FarmingModelHarvest.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/FarmingModelHarvestPostRH.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/manager/CoreAPIManager.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/BaseResponseHandler.kt
  • offline-core/src/main/java/com/mindtree/bridge/coreapi/offline/SyncQueueProcessor.java
  • offline-core/src/main/java/com/mindtree/bridge/coreapi/offline/manager/OperationManagerImpl.java
  • core-api/src/main/java/com/mindtree/bridge/coreapi/impl/CoreAPIDefaultImpl.java