Skip to main content
POST
/
v1
/
projects
/
{project_id}
/
entities
/
link-by-filters
Link Entities by Filters
const options = {
  method: 'POST',
  headers: {
    'x-api-key': '<x-api-key>',
    'x-organization-id': '<x-organization-id>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({entity_type: '<string>', filters: {}})
};

fetch('https://api.dcycle.io/v1/projects/{project_id}/entities/link-by-filters', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
{
  "created": 123,
  "skipped": 123
}

Link Entities by Filters

Link all entities that match a given filter to a project — without needing to enumerate individual IDs. This is the most efficient way to associate large historical datasets or ongoing data streams to a project. The operation is idempotent: entities already linked are skipped, so it is safe to call repeatedly with the same filters.
New API: This endpoint is part of the new API architecture.

Request

Headers

x-api-key
string
required
Your API key for authenticationExample: sk_live_1234567890abcdef
x-organization-id
string
required
Your organization UUIDExample: a8315ef3-dd50-43f8-b7ce-d839e68d51fa

Path Parameters

project_id
string
required
The UUID of the project to link entities toExample: b7f2a1c3-4d5e-6f7a-8b9c-0d1e2f3a4b5c

Body Parameters

entity_type
string
required
The type of entities to link. Determines which filter fields are valid.Available values: logistic_requests, logistic_recharges, logistic_packages, invoices, file_readings
filters
object
Filter criteria for selecting entities. The valid fields depend on entity_type — see the tables below.Pass an empty object {} to link all entities of the given type to the project.

Filter Fields by Entity Type

FieldTypeDescription
searchstringSearch across movement ID and stretch ID
clientsarray[string]Filter by client name(s)
trip_date_fromstring (YYYY-MM-DD)Filter by trip date >=
trip_date_untilstring (YYYY-MM-DD)Filter by trip date <=
vehicle_typearray[string]Filter by vehicle type(s)
uploaded_byarray[string (UUID)]Filter by uploader user ID(s)
file_idarray[string (UUID)]Filter by source file ID(s)
created_at_fromstring (YYYY-MM-DD)Filter by creation date >=
created_at_tostring (YYYY-MM-DD)Filter by creation date <=
Unknown filter keys return a 422 error. Only the fields listed above are accepted.
FieldTypeDescription
vehicle_typearray[string]Filter by vehicle type(s)
fuel_idarray[string (UUID)]Filter by fuel ID(s)
vehicle_license_platearray[string]Filter by license plate(s)
file_idarray[string (UUID)]Filter by source file ID(s)
date_fromstring (YYYY-MM-DD)Filter by recharge date >=
date_untilstring (YYYY-MM-DD)Filter by recharge date <=
created_at_fromstring (YYYY-MM-DD)Filter by creation date >=
created_at_tostring (YYYY-MM-DD)Filter by creation date <=
FieldTypeDescription
created_at_fromstring (YYYY-MM-DD)Filter by creation date >=
created_at_tostring (YYYY-MM-DD)Filter by creation date <=
FieldTypeDescription
typesarray[string]Filter by invoice type(s)
statusesarray[string]Filter by invoice status(es)
facility_idsarray[string (UUID)]Filter by facility ID(s)
start_datestring (YYYY-MM-DD)Filter by invoice date >=
end_datestring (YYYY-MM-DD)Filter by invoice date <=
FieldTypeDescription
linkedbooleantrue = only already-linked readings; false = only unlinked readings

Response

created
integer
Number of new links created
skipped
integer
Number of entities that were already linked (skipped)

Examples

curl -X POST "https://api.dcycle.io/v1/projects/b7f2a1c3-4d5e-6f7a-8b9c-0d1e2f3a4b5c/entities/link-by-filters" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}" \
  -H "Content-Type: application/json" \
  -d '{
    "entity_type": "logistic_requests",
    "filters": {
      "trip_date_from": "2024-01-01",
      "trip_date_until": "2024-03-31",
      "clients": ["AMAZON"]
    }
  }'

Successful Response

{
  "created": 347,
  "skipped": 12
}

Common Errors

404 Not Found

Cause: Project not found or doesn’t belong to your organization
{
  "code": "NOT_FOUND",
  "detail": "Project not found"
}

422 Invalid Filters

Cause: An unknown filter key was passed for the given entity_type
{
  "code": "INVALID_FILTERS",
  "detail": "Unknown filter key: 'foo'"
}
Solution: Check the filter fields table for your entity_type above. Only the listed fields are accepted — extra keys are rejected.

Link Entities

Link specific entities by ID

Unlink Entities

Remove entity-project associations