How to use the metrics REST API?

Good morning!

I would like to query the snapcraft endpoints directly, but am having difficulty doing so.

Upon sending the request I receive this error:

  "error_list": [
      "message": "The request is missing an Authorization header field containing a valid macaroon",
      "code": "macaroon-authorization-required",
      "extra": {
        "realm": "Developer Portal"

I would appreciate guidance on where am I going wrong?

Steps taken


I have exported a macaroon with the package_metrics which is valid and works in conjunction with snapcraft itself.

email: ...
username: dwd-daniel
id: ...
permissions: package_metrics
channels: no restrictions
expires: 2025-04-18T08:05:52.000Z  

The request

I have crafted a curl request:

curl -v \
        -X POST \
        -H 'Snap-Device-Series: 16' \
        -H "Authorization: Macaroon ${ACL}" \
        -H 'Content-Type: application/json; charset=utf-8' \
        --data "${PAYLOAD}" \
  • ACL is populated with the b64encoded macaroon
  • The PAYLOAD contains, with SNAP_ID replaced appropriately:
  "filters": [
            "snap_id": "${SNAP_ID}", 
            "metric_name": "daily_device_change", 
            "start": "2024-01-01", 
            "end": "2024-06-26"

Best regards