APIs & services / asset-service

Create a land or cattle asset.

Endpointtoday's app
Call
POST /gateway/asset-service/api/v1/assets/
Service
asset-service
Features
Land assets, Leased land, Livestock
When
Queued sync (FARMER_ASSETS POST)
Auth
X-SESSIONID stamped when queued (CoreAPI dooWithRetry); X-REQUESTID idempotency key
In the App Service

Use case

Creates a land, leased-land or livestock asset that the cadre added on the Land or Livestock screens. The save writes farmerassets plus a FARMER_ASSETS POST sync-ledger entry. FarmerAssetsWorker resolves owningEntityId from the farmer's app id (replacePlatformValues), builds FarmerAssets.post() and queues it with dooWithRetry. The row is marked IN_SYNC_QUEUE. On 2xx, FarmerAssetsPostRH parses the plain-integer body as the new asset id, sets the row to SYNC_DONE and clears ledger dependencies (for example the geofence upload). On error it returns TryAgain.LATER. If the raw response contains "Integrity" and the quantity is null, it sets totalQuantity.value=0.0 and rewrites the queued operation.

Headers

HeaderValueNotes
X-SESSIONID<session id>Stamped by CoreAPI when the queued operation runs (CoreAPIDefaultImpl.doOperation). On a 401 the token is invalidated and the call retried. BaseResponseHandler also refreshes the session after a 500 on a gateway URL (first 5 attempts).
X-REQUESTID<uuid v4>Idempotency key added by the offline queue (OperationManagerImpl). A 409 replaces it with a new UUID. It is removed for multipart requests.
Content-Typeapplication/jsonSet by the HTTP client for JSON bodies.

Request

Example request body (synthetic data)
{
  "id": null,
  "owningEntityId": "880001",
  "assetCode": "AST-0001",
  "dateOfPurchase": null,
  "ownerEntityType": {
    "code": "OWNER_ENTITY.IE",
    "refClass": {
      "code": "OWNER_ENTITY"
    }
  },
  "assetCategory": {
    "code": "ASSET_CATEGORY.LAND",
    "refClass": {
      "code": "ASSET_CATEGORY"
    },
    "labels": [
      {
        "id": 1,
        "text": "Land",
        "language": {
          "code": "ENG",
          "label": "English"
        }
      }
    ]
  },
  "assetSubCategory": {
    "code": "ASSET_SUB_CATEGORY.LAND_OWNED",
    "refClass": {
      "code": "ASSET_SUB_CATEGORY"
    },
    "labels": [
      {
        "id": 2,
        "text": "Owned",
        "language": {
          "code": "ENG",
          "label": "English"
        }
      }
    ]
  },
  "assetFunctionality": {
    "code": "ASSET_FUNCTIONALITY.IRRIGATED",
    "refClass": {
      "code": "ASSET_FUNCTIONALITY"
    },
    "labels": []
  },
  "quality": null,
  "totalQuantity": {
    "id": 9001,
    "value": 1.5,
    "uoM": {
      "symbol": "ac",
      "code": "UOM.ACRE",
      "name": "Acre",
      "description": null,
      "measurementType": {
        "code": "AREA",
        "name": "Area",
        "description": null,
        "globalRefClass": {
          "code": "MEASUREMENT_TYPE",
          "name": null,
          "description": null
        }
      }
    }
  },
  "nameList": [
    {
      "id": 77,
      "text": "Survey 12/3",
      "language": {
        "code": "ENG",
        "label": "English"
      }
    }
  ],
  "assetSpecsList": [
    {
      "id": 300,
      "specName": "SURVEY_NUMBER",
      "specValue": "12/3",
      "uuid": "0f0e0d0c-0000-4000-8000-000000000001"
    }
  ],
  "appMillMetadata": {
    "ie_appId": "IE-APP-UUID-0001"
  },
  "assetCheckSum": "9e107d9d372bb6826bd81d3542a419d6",
  "authenticated": true,
  "notes": null,
  "isLeased": false,
  "leaseStatus": null,
  "leaseType": null,
  "leasedFromOwningEntityId": null,
  "leasedToOwningEntityId": null,
  "leasedFromAssetId": null,
  "leasedFromWorknodeCode": null,
  "leasedFromWorknodeType": null,
  "isActive": true,
  "inactiveReason": null,
  "inactiveAt": null,
  "createdAt": null,
  "lastModifiedAt": null,
  "appCreatedAt": "1748772000000",
  "appLastModifiedAt": "1748858400000",
  "createdByApp": 1,
  "lastModifiedByApp": 1,
  "createdFromDevice": "DEVICE-XXXX",
  "lastUpdatedFromDevice": "DEVICE-XXXX"
}
FieldTypeRequiredNotes
idintNoServer asset id. 0 or null when creating.
owningEntityIdstringYesFarmer IE id (server). If it is not numeric, replacePlatformValues swaps in the server IE id resolved from appMillMetadata.ie_appId.
assetCodestringNoBusiness code of the asset. Also sent with the geofence upload.
dateOfPurchasestring|nullNoLivestock purchase date.
ownerEntityType.codestringYesOWNER_ENTITY.IE for farmers, OWNER_ENTITY.BRIDGE_USER for the cadre's own assets (FarmerAssetsMapper).
assetCategory.code / assetSubCategory.code / assetFunctionality.code / quality.codestringYesValues from the asset ref data (land or livestock picker on the Land and Livestock screens).
*.labels[]arrayNoLocalised labels, stored in asset_*_labels tables.
totalQuantity.valuedoubleYesLand extent (acres) or head count, from the Extent field. On an "Integrity" error, the RH sets a null value to 0.0 and re-queues.
totalQuantity.uoMobjectNoUnit of measure (code, symbol, measurementType).
nameList[].textstringNoAsset name or survey label. PII: may contain survey or land identifiers.
assetSpecsList[]arrayNospecName/specValue pairs (for example survey number). PII: land record identifiers.
appMillMetadata.ie_appIdstringNoLocal app id of the farmer, used to resolve owningEntityId offline.
assetCheckSumstringNoMD5 of the asset name plus total quantity (IeAsset.setMD5Hash). The server uses it to detect checksum mismatches (ERR_PLATFORM_ASSET_CHECKSUM_MISMATCH).
authenticatedbooleanNoLand authenticated toggle.
isLeased, leaseStatus, leaseType, leasedFrom*/leasedTo*mixedNoLeased-land screen fields.
isActive, inactiveReason, inactiveAtboolean/string/longNoSoft-delete state. inactiveReason also goes in the DELETE query.
createdAt, lastModifiedAt, appCreatedAt, appLastModifiedAt, createdByApp, lastModifiedByApp, createdFromDevice, lastUpdatedFromDevicestring/longNoAudit fields. Device ids are device identifiers.
geoFencingFileName, geoFencingCreatedOn, geoFencingFilePath, geoFencingIdstring/intNoLocal-only Room columns that Moshi/Gson also serialise. The server is not known to read them.

Response

Example response body (synthetic data)
5501
FieldTypeRequiredNotes
(body)int (plain text)New server asset id. Saved only if rawResponse.toIntOrNull() is not null; otherwise the success is silently ignored.

Errors

StatusWhenWhat the app does
401Session expiredCoreAPI invalidates the session id and retries once. If it still fails, the response handler returns TryAgain.LATER and the operation stays in the queue.
409Duplicate X-REQUESTIDSyncQueueProcessor records the request id and swaps in a fresh X-REQUESTID for the next attempt.
4xx/5xx (other)Server rejects or failsonError returns TryAgain.LATER (FarmerAssetsPostRH). Each failure is logged in the local error_log table (URL, body, headers). Every 10th attempt (up to attempt 5000) the whole operation is copied to Firestore urvi_sync_log. A 500 on a gateway URL in the first 5 attempts forces a session refresh.

Source

  • data/src/main/java/org/mindtree/app/agricultor/data/entity/FarmerAssets.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/work/FarmerAssetsWorker.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/FarmerAssetsPostRH.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/BaseResponseHandler.kt
  • core-api/src/main/java/com/mindtree/bridge/coreapi/impl/CoreAPIDefaultImpl.java