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

# Assess Deforestation Risk for a GeoJSON Polygon

> Run a pre-assessment EUDR risk check on a GeoJSON polygon using Country Risk Matrix lookups and Sentinel-2 satellite deforestation analysis.

Before committing a polygon to a full ingestion pipeline, you can use this endpoint to run an on-the-fly deforestation risk pre-assessment. Submit a GeoJSON geometry and AgriBackup will query the Country Risk Matrix and execute a live Sentinel-2 NDVI analysis, returning a risk classification and satellite metrics without creating any persisted records or consuming batch quota.

**`POST /api/v1/enterprise/eudr/risk/assess-polygon`**

## Request Body

<ParamField body="geoJson" type="object" required>
  A valid GeoJSON geometry object representing the polygon to assess. The object must conform to the GeoJSON specification (RFC 7946). Coordinates are expressed as `[longitude, latitude]` pairs, and the polygon ring must be closed (first and last coordinate must match).

  ```json theme={null}
  {
    "type": "Polygon",
    "coordinates": [
      [
        [36.80, -1.30],
        [36.85, -1.30],
        [36.85, -1.25],
        [36.80, -1.25],
        [36.80, -1.30]
      ]
    ]
  }
  ```
</ParamField>

## Code Examples

<CodeGroup>
  ```python Python theme={null}
  import agribackup
  from agribackup.rest import ApiException

  configuration = agribackup.Configuration(host="https://live.agribackup.com/api/v1")
  configuration.api_key["ApiKeyAuth"] = "sk_live_YOUR_API_KEY"

  payload = {
      "geoJson": {
          "type": "Polygon",
          "coordinates": [
              [
                  [36.80, -1.30],
                  [36.85, -1.30],
                  [36.85, -1.25],
                  [36.80, -1.25],
                  [36.80, -1.30]
              ]
          ]
      }
  }

  with agribackup.ApiClient(configuration) as api_client:
      try:
          api_instance = agribackup.EnterpriseRiskManagementApi(api_client)
          response = api_instance.assess_polygon_risk(body=payload)
          print(response)
      except ApiException as e:
          print("Exception when calling API: %s\n" % e)
  ```

  ```javascript Node.js theme={null}
  import { AgriBackupClient } from "@agribackup/sdk";

  const client = new AgriBackupClient({
    apiKey: "sk_live_YOUR_API_KEY",
    baseUrl: "https://live.agribackup.com/api/v1",
  });

  async function assessPolygonRisk() {
    try {
      const response = await client.management.assessPolygonRisk({
        geoJson: {
          type: "Polygon",
          coordinates: [
            [
              [36.80, -1.30],
              [36.85, -1.30],
              [36.85, -1.25],
              [36.80, -1.25],
              [36.80, -1.30],
            ],
          ],
        },
      });
      console.log(response);
    } catch (error) {
      console.error(error);
    }
  }

  assessPolygonRisk();
  ```

  ```bash cURL theme={null}
  curl --request POST \
    --url https://live.agribackup.com/api/v1/enterprise/eudr/risk/assess-polygon \
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer sk_live_YOUR_API_KEY" \
    --data '{
      "geoJson": {
        "type": "Polygon",
        "coordinates": [
          [
            [36.80, -1.30],
            [36.85, -1.30],
            [36.85, -1.25],
            [36.80, -1.25],
            [36.80, -1.30]
          ]
        ]
      }
    }'
  ```
</CodeGroup>

## Response

A `200 OK` response indicates the risk assessment completed synchronously. The body contains satellite NDVI metrics, the country risk classification, and a deforestation probability score.

```json theme={null}
{
  "countryCode": "KEN",
  "countryName": "Kenya",
  "countryRiskLevel": "STANDARD",
  "countryRiskJustification": "Standard default risk assigned",
  "satelliteAnalysisState": "COMPLETED",
  "deforestationDetected": false,
  "deforestationProbability": 0.05,
  "ndviBaseline": 0.72,
  "ndviCurrent": 0.70,
  "ndviChange": -0.02,
  "dataSource": "COPERNICUS-SENTINEL-2"
}
```

<ResponseField name="countryCode" type="string">
  ISO-3166-1 alpha-3 country code detected from the polygon's centroid (e.g., `KEN`, `BRA`, `IDN`). May be `null` if the coordinate falls in international waters or an unmapped territory.
</ResponseField>

<ResponseField name="countryName" type="string">
  Human-readable name of the detected country. May be `null` in the same circumstances as `countryCode`.
</ResponseField>

<ResponseField name="countryRiskLevel" type="string">
  The EUDR Country Risk Matrix classification for the detected country. One of `LOW`, `STANDARD`, or `HIGH`. `HIGH` risk countries require additional due-diligence evidence before a DDS can be submitted.
</ResponseField>

<ResponseField name="countryRiskJustification" type="string">
  A plain-language explanation for the assigned risk level, derived from the Country Risk Matrix dataset.
</ResponseField>

<ResponseField name="satelliteAnalysisState" type="string">
  Indicates the completion state of the Sentinel-2 analysis. Possible values:

  * `COMPLETED` — analysis finished successfully
  * `PHASE_2_SAR_FAILOVER_PENDING` — optical imagery was insufficient; SAR fallback is queued
  * `UNSUPPORTED_OR_EMPTY_ACQUISITION` — no satellite data is available for this geometry
</ResponseField>

<ResponseField name="deforestationDetected" type="boolean">
  `true` if on-the-fly analysis triggered a deforestation alert for the submitted polygon; `false` otherwise.
</ResponseField>

<ResponseField name="deforestationProbability" type="number">
  A decimal value between `0.0` and `1.0` representing the NDVI-derived probability of deforestation activity. Values above `0.30` should be treated as elevated risk.
</ResponseField>

<ResponseField name="ndviBaseline" type="number">
  The historical baseline NDVI index for the polygon area, used as the reference point for change detection.
</ResponseField>

<ResponseField name="ndviCurrent" type="number">
  The most recent NDVI index reading from the latest Sentinel-2 acquisition over the polygon.
</ResponseField>

<ResponseField name="ndviChange" type="number">
  The delta between `ndviCurrent` and `ndviBaseline`. Negative values indicate vegetation loss. Values below `-0.10` warrant closer inspection.
</ResponseField>

<ResponseField name="dataSource" type="string">
  The satellite programme used for analysis, typically `COPERNICUS-SENTINEL-2`. Fallback analyses may report `SENTINEL_1_SAR`.
</ResponseField>

## Error Responses

| HTTP Status             | Error Code          | Description                                                                                                                                 |
| ----------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `400 Bad Request`       | `VALIDATION_FAILED` | The `geoJson` field is missing, malformed, or the polygon coordinates are invalid (e.g., ring not closed, self-intersecting).               |
| `401 Unauthorized`      | `UNAUTHORIZED`      | The `Authorization` header is missing or the bearer token is not recognised.                                                                |
| `403 Forbidden`         | `FORBIDDEN`         | Your API key does not have the required scope to access risk assessment endpoints.                                                          |
| `429 Too Many Requests` | `RATE_LIMITED`      | You have exceeded the hourly rate limit. Check the `X-RateLimit-Reset` response header for the UTC epoch second at which your quota resets. |

```json theme={null}
{
  "code": "VALIDATION_FAILED",
  "message": "Invalid polygon coordinates",
  "details": [
    {
      "code": "INVALID_COORDINATE_CLOSURE",
      "field": "geoJson.coordinates[0]",
      "issue": "Polygon ring is not closed — the first and last coordinate must be identical."
    }
  ]
}
```
