Skip to main content
GET
https://api.dcycle.io
/
v1
/
logistics
/
packages
Get Packages
const options = {
  method: 'GET',
  headers: {'x-api-key': '<x-api-key>', 'x-organization-id': '<x-organization-id>'}
};

fetch('https://api.dcycle.io/v1/logistics/packages', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
{
  "page": 123,
  "size": 123,
  "total": 123,
  "items": [
    {
      "id": "<string>",
      "shipment_id": "<string>",
      "package_key": "<string>",
      "client_billing_id": "<string>",
      "weight_kg": 123,
      "total_distance_km": 123,
      "total_co2e": 123,
      "status": "<string>",
      "created_at": {},
      "updated_at": {}
    }
  ]
}

Get Packages

Retrieve all logistics packages created by your organization with pagination support. Packages group multiple legs of a shipment and provide aggregated distance and emissions data.
New API: This endpoint is part of the new API architecture with improved design and maintainability.

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

Query Parameters

page
integer
default:"1"
Page number to retrieveExample: 1
size
integer
default:"10"
Number of items per page (1-100)Example: 50
movement_id
string
Filter packages by movement ID (shipment identifier). Use this to get all packages belonging to a specific shipment.Example: SHIP-2024-001
client
string
Filter packages by client identifier. Use this to get all packages for a specific client (e.g., corporate customers like Amazon).Example: AMAZON
package_key
string
Filter by package key to find a specific package. Useful when you have the package identifier from a label or tracking system.Note: When filtering by package_key, the response includes the legs array with the complete journey details.Example: 26830007899150601093463

Response

page
integer
Current page number
size
integer
Number of items per page
total
integer
Total number of packages
items
array
Array of package objects

Example

curl -X GET "https://api.dcycle.io/v1/logistics/packages?page=1&size=10" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}"

Filter by Shipment

Get all packages for a specific shipment:
curl -X GET "https://api.dcycle.io/v1/logistics/packages?movement_id=SHIP-2024-001" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}"

Filter by Client (Corporate Customer Report)

Get all packages for a specific client like Amazon to generate their environmental impact report:
curl -X GET "https://api.dcycle.io/v1/logistics/packages?client=AMAZON" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}"

Find Package by Key (with Complete Journey)

Find a specific package using its key from the shipping label. When filtering by package_key, the response includes the complete journey with all legs:
curl -X GET "https://api.dcycle.io/v1/logistics/packages?package_key=26830007899150601093463" \
  -H "x-api-key: ${DCYCLE_API_KEY}" \
  -H "x-organization-id: ${DCYCLE_ORG_ID}"
Response when filtering by package_key:
{
  "page": 1,
  "size": 10,
  "total": 1,
  "items": [
    {
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "shipment_id": "SHIP-2024-001",
      "package_key": "26830007899150601093463",
      "weight_kg": 15.0,
      "total_distance_km": 850.5,
      "total_co2e": 42.75,
      "status": "active",
      "legs": [
        {
          "id": "leg-uuid-1",
          "origin": "Madrid Hub",
          "destination": "Valencia Hub",
          "distance_km": 350.2,
          "co2e": 17.51
        },
        {
          "id": "leg-uuid-2",
          "origin": "Valencia Hub",
          "destination": "Barcelona Hub",
          "distance_km": 350.3,
          "co2e": 17.52
        },
        {
          "id": "leg-uuid-3",
          "origin": "Barcelona Hub",
          "destination": "Final Address, Barcelona",
          "distance_km": 150.0,
          "co2e": 7.72
        }
      ]
    }
  ]
}

Successful Response

{
  "page": 1,
  "size": 10,
  "total": 25,
  "items": [
    {
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "shipment_id": "SHIP-2024-001",
      "package_key": "PKG-2024-123456",
      "client_billing_id": "CLIENT-001",
      "weight_kg": 15.0,
      "total_distance_km": 850.5,
      "total_co2e": 42.75,
      "status": "active",
      "created_at": "2024-11-24T10:30:00Z",
      "updated_at": "2024-11-24T14:45:00Z"
    },
    {
      "id": "b2c3d4e5-f6a7-8901-bcde-f23456789012",
      "shipment_id": "SHIP-2024-001",
      "package_key": "PKG-2024-123457",
      "client_billing_id": "CLIENT-001",
      "weight_kg": 22.5,
      "total_distance_km": 850.5,
      "total_co2e": 64.12,
      "status": "active",
      "created_at": "2024-11-24T10:31:00Z",
      "updated_at": "2024-11-24T14:46:00Z"
    }
  ]
}

Common Errors

401 Unauthorized

Cause: Missing or invalid API key
{
  "detail": "Invalid API key",
  "code": "INVALID_API_KEY"
}
Solution: Verify your API key is valid and active. Get a new one from Settings -> API.

404 Not Found

Cause: Organization not found
{
  "code": "ORGANIZATION_NOT_FOUND",
  "detail": "Organization with id=UUID('...') not found"
}
Solution: Verify that the x-organization-id header contains a valid organization UUID.

Use Cases

Corporate Client Environmental Report

Generate an environmental impact report for a corporate client (e.g., Amazon requesting their carbon footprint from your logistics operations):
def generate_client_environmental_report(client_name: str) -> dict:
    """Generate environmental impact report for a corporate client"""
    all_packages = []
    page = 1

    # Paginate through all packages for this client
    while True:
        response = requests.get(
            "https://api.dcycle.io/v1/logistics/packages",
            headers=headers,
            params={"client": client_name, "page": page, "size": 100}
        )

        data = response.json()
        all_packages.extend(data['items'])

        if len(data['items']) < 100:
            break
        page += 1

    # Calculate totals
    total_packages = len(all_packages)
    total_weight = sum(pkg['weight_kg'] or 0 for pkg in all_packages)
    total_distance = sum(pkg['total_distance_km'] or 0 for pkg in all_packages)
    total_co2e = sum(pkg['total_co2e'] or 0 for pkg in all_packages)

    return {
        "client": client_name,
        "report_date": datetime.now().isoformat(),
        "total_packages": total_packages,
        "total_weight_kg": total_weight,
        "total_distance_km": total_distance,
        "total_co2e_kg": total_co2e,
        "avg_co2e_per_package": total_co2e / total_packages if total_packages > 0 else 0,
    }

# Example: Generate report for Amazon
report = generate_client_environmental_report("AMAZON")
print(f"=== Environmental Report for {report['client']} ===")
print(f"Packages delivered: {report['total_packages']}")
print(f"Total weight transported: {report['total_weight_kg']:.2f} kg")
print(f"Total distance: {report['total_distance_km']:.2f} km")
print(f"Total CO2e emissions: {report['total_co2e_kg']:.2f} kg")
print(f"Average emissions per package: {report['avg_co2e_per_package']:.2f} kg CO2e")

End Customer Package Impact (Label Lookup)

Provide environmental impact information to an end customer who received a package. The customer can look up their package using the tracking code from the label:
def get_package_impact_for_customer(package_key: str) -> dict:
    """Get package environmental impact for end customer display"""
    # Find the package by its key
    response = requests.get(
        "https://api.dcycle.io/v1/logistics/packages",
        headers=headers,
        params={"package_key": package_key}
    )

    result = response.json()

    if not result['items']:
        return {"error": "Package not found"}

    package = result['items'][0]

    # Get detailed journey if needed
    detail_response = requests.get(
        f"https://api.dcycle.io/v1/logistics/packages/{package['id']}",
        headers=headers
    )
    package_detail = detail_response.json()

    # Build customer-friendly response
    return {
        "package_key": package_key,
        "total_distance_km": package['total_distance_km'],
        "total_co2e_kg": package['total_co2e'],
        "journey_legs": len(package_detail.get('legs', [])),
        "environmental_context": {
            "equivalent_car_km": package['total_co2e'] / 0.12 if package['total_co2e'] else 0,  # ~120g CO2/km for avg car
            "equivalent_trees_day": package['total_co2e'] / 0.022 if package['total_co2e'] else 0,  # ~22g CO2 absorbed per tree per day
        }
    }

# Example: Customer Pedro looks up his package
package_info = get_package_impact_for_customer("26830007899150601093463")
if "error" not in package_info:
    print(f"Your package traveled {package_info['total_distance_km']:.0f} km")
    print(f"Carbon footprint: {package_info['total_co2e_kg']:.2f} kg CO2e")
    print(f"Equivalent to driving a car {package_info['environmental_context']['equivalent_car_km']:.1f} km")

Calculate Shipment Total Emissions

Get total emissions for all packages in a shipment:
def get_shipment_emissions(movement_id: str) -> dict:
    """Calculate total emissions for a shipment"""
    response = requests.get(
        "https://api.dcycle.io/v1/logistics/packages",
        headers=headers,
        params={"movement_id": movement_id}
    )

    data = response.json()

    total_distance = sum(pkg['total_distance_km'] or 0 for pkg in data['items'])
    total_co2e = sum(pkg['total_co2e'] or 0 for pkg in data['items'])
    total_weight = sum(pkg['weight_kg'] or 0 for pkg in data['items'])

    return {
        "movement_id": movement_id,
        "package_count": len(data['items']),
        "total_weight_kg": total_weight,
        "total_distance_km": total_distance,
        "total_co2e_kg": total_co2e
    }

# Example usage
shipment_summary = get_shipment_emissions("SHIP-2024-001")
print(f"Shipment {shipment_summary['movement_id']}:")
print(f"  Packages: {shipment_summary['package_count']}")
print(f"  Total weight: {shipment_summary['total_weight_kg']:.2f} kg")
print(f"  Total emissions: {shipment_summary['total_co2e_kg']:.2f} kg CO2e")

Export Packages Report

Generate a report of all packages with their emissions:
import csv

def export_packages_report(filename="packages_report.csv"):
    """Export all packages to CSV report"""
    all_packages = []
    page = 1

    while True:
        response = requests.get(
            "https://api.dcycle.io/v1/logistics/packages",
            headers=headers,
            params={"page": page, "size": 100}
        )

        data = response.json()
        all_packages.extend(data['items'])

        if len(data['items']) < data['size']:
            break
        page += 1

    fields = ['package_key', 'shipment_id', 'weight_kg',
              'total_distance_km', 'total_co2e', 'created_at']

    with open(filename, 'w', newline='') as csvfile:
        writer = csv.DictWriter(csvfile, fieldnames=fields)
        writer.writeheader()

        for pkg in all_packages:
            row = {field: pkg.get(field) for field in fields}
            writer.writerow(row)

    print(f"Exported {len(all_packages)} packages to {filename}")

export_packages_report()