Documentatie/Create-Cropfield.md

132 lines
3.9 KiB
Markdown

## Create cropfield with the farmmaps API
If there aren't any relevant cropfields in FarmMaps, you can create them yourself by executing the following steps:
* Execute the following REST call to create the 'my_drive' item which contains the needed itemcode:
> Request
```
GET /api/v1/folders/my_drive
```
> Response 200 Succes
```javascript
{
"url": "string",
"code": "string",
"name": "string",
"created": "2019-12-18T09:49:35.741Z",
"updated": "2019-12-18T09:49:35.741Z",
"dataDate": "2019-12-18T09:49:35.741Z",
"itemType": "string",
"sourceTask": "string",
"size": 0,
"state": 0,
"thumbnail": true
}
```
* Create a 'FOLDER' item as a child of the 'my_drive' item.
>Request
```javascript
POST /api/v1/items
{
"parentCode": "{my_drive_code}",
"itemType": "FOLDER",
"name": "string",
"data": {},
"dataDate": "2019-12-18T09:59:18.893Z",
"geometry": {},
"tags": [
"string"
]
}
```
> Response 201 Created
```javascript
{
"parentCode": "string",
"geometry": {},
"data": {},
"tags": [
"string"
],
"url": "string",
"code": "string",
"name": "string",
"created": "2019-12-18T10:16:21.455Z",
"updated": "2019-12-18T10:16:21.455Z",
"dataDate": "2019-12-18T10:16:21.455Z",
"itemType": "string",
"sourceTask": "string",
"size": 0,
"state": 0,
"thumbnail": true
}
```
Response 401 Not authenticated
Response 403 No WRITE permissions in parent item
Response 404 Parent Item not found
* Create a 'vnd.farmmaps.itemtype.cropfield' item as a child of the 'FOLDER' item.
Needs to contain dataDate and dataEndDate to specify cropfield season.
dataDate needs to be before dataEndDate and cannot be the same day.
The data field needs to contain the startDate and endDate keys with the same values as dataDate(startDate) and dataEndDate(endDate)
> Request
```javascript
POST /api/v1/items
{
"parentCode": "{FOLDER_item_code}",
"itemType": "vnd.farmmaps.itemtype.cropfield",
"name": "cropfield for VRA",
"dataDate": "2019-1-18T10:16:21.455Z",
"dataEndDate": "2019-12-18T10:16:21.455Z",
"data": {"startDate": "2019-1-18T10:16:21.455Z", "endDate": "2019-12-18T10:16:21.455Z"},
"geometry": {"type":"Polygon","coordinates":[[[6.09942873984307,53.070025028087],[6.09992507404607,53.0705617890585],[6.10036959220086,53.0710679529031],[6.10065149010421,53.0714062774307],[6.10087493644271,53.0716712354474],[6.10091082982487,53.0716936039203],[6.10165087441291,53.0712041549161],[6.10204994718318,53.0709349338005],[6.10263143118855,53.0705789370018],[6.10311578125011,53.0702657538294],[6.10331686552072,53.0701314102389],[6.103326530575,53.070119463569],[6.10309137950343,53.0699829669055],[6.10184241586523,53.0692902201371],[6.10168497998891,53.0691984306747],[6.10092987659869,53.0694894453514],[6.09942873984307,53.070025028087]]]}
}
```
> Response 201 Created
```Javascript
{
"parentCode": "string",
"geometry": {},
"data": {},
"tags": [
"string"
],
"url": "string",
"code": "string",
"name": "string",
"created": "2019-12-18T10:16:21.455Z",
"updated": "2019-12-18T10:16:21.455Z",
"dataDate": "2019-12-18T10:16:21.455Z",
"itemType": "string",
"sourceTask": "string",
"size": 0,
"state": 0,
"thumbnail": true
}
```
* Execute the workflow task with the cropfield item code.
This steps makes sure that FarmMaps aggregates all needed data for the cropfield.
> Request
```javascript
POST /api/v1/items/{code}/tasks
{
"taskType": "vnd.farmmaps.task.workflow"
}
```
> Response 201
```javascript
{
"code": "string",
"taskType": "vnd.farmmaps.task.workflow",
"delay": "",
"attributes": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
}
}
```
Response 400 Tasktype not found
Response 401 Not authenticated
Response 403 No WRITE permissions in item
Response 404 Item not found