Working with Collections
The Collections feature is in beta release
For creating and editing collections through the web interface, see the user guide. This page is for working with collections via the API.
Using chloris-app-sdk (Python)
You can create or update a collection in the chloris-app-sdk by using the client.put_collection function.
Here is an example which will create a new collection:
from chloris_app_sdk import ChlorisAppClient
# create the client
client = ChlorisAppClient(
organization_id="your-organization-id",
refresh_token="your-refresh-token", # env: CHLORIS_REFRESH_TOKEN
# or
# id_token="your-id-token" # env: CHLORIS_ID_TOKEN
)
# create or update a collection
collection = client.put_collection(
collection_entry={
"organizationId": "your-organization-id",
# "reportingUnitId": "your-collection-reporting-unit-id", # include to edit an existing collection
"label": "your-collection-name",
"description": "your-collection-description"
"reportingUnitIds": ["reportingUnitId1", "reportingUnitId2", ...]
}
)
# the resulting collection entry
print(collection)
# {
# 'organizationId': '...',
# 'reportingUnitId': '...',
# 'collectionId': '...',
# 'branchId': '...',
# 'label': '...',
# 'description': '...',
# 'reportingUnitIds': [...],
# 'updatedAt': '...',
# 'createdAt': '...',
# 'createdBy': '...',
# 'hidden': False
# }
Using the REST API (JavaScript)
Here is an example of creating a collection using the aws-sdk in JavaScript:
// node-specific imports
import fetch from "node-fetch";
const organizationId = "your-organization-id";
// Create a collection
const collection = await (
await fetch("https://app.chloris.earth/api/collection", {
method: "PUT",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${yourApiIdToken}`,
},
body: JSON.stringify({
organizationId: organizationId,
// reportingUnitId: "yourReportingUnitId", // include to edit an existing collection
label: "your-label"
description: "your-description",
reportingUnitIds: [...]
}),
})
).json();