{
  "openapi": "3.0.3",
  "info": {
    "title": "MovePacket API",
    "version": "0.1.0",
    "description": "Private beta contract. Check /site-status.json before using the hosted API: api_available must be true. API access requires a provisioned workspace key. Device connections, webhooks, MCP, and public signup are not implemented."
  },
  "servers": [
    {
      "url": "https://movepacket.com",
      "description": "Private beta origin; access and activation required"
    },
    {
      "url": "http://127.0.0.1:8787",
      "description": "Local development with a locally provisioned key"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Activities",
      "description": "Upload original FIT files and retrieve decoded activity data"
    }
  ],
  "paths": {
    "/v1/activities": {
      "post": {
        "tags": [
          "Activities"
        ],
        "operationId": "uploadActivity",
        "summary": "Upload a FIT activity",
        "description": "Send raw FIT bytes, not multipart or JSON. Maximum 4 MiB. The same bytes in the same workspace reuse one activity. HTTP 202 means processing is pending; 200 means the returned activity is already ready or failed. Concurrent uploads converge on one ID; duplicate is advisory.",
        "requestBody": {
          "required": true,
          "content": {
            "application/vnd.ant.fit": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing terminal activity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadResponse"
                }
              }
            }
          },
          "202": {
            "description": "Activity accepted for asynchronous processing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadResponse"
                }
              }
            },
            "headers": {
              "Location": {
                "description": "Relative status URL",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, or revoked key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "File exceeds 4 MiB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Unsupported media type",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "FIT validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service or stored object unavailable; hosted beta may not be open",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Activities"
        ],
        "operationId": "listActivities",
        "summary": "List activities",
        "description": "Workspace-scoped, newest first (created_at then id, both descending). Offset pages can shift when new activities are added. stats always describes the entire workspace, independent of filters.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Case-sensitive activity ID substring; trimmed",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "processing combines received and queued",
            "schema": {
              "type": "string",
              "enum": [
                "received",
                "queued",
                "processing",
                "ready",
                "failed"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100000,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching activities and workspace counts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ActivityList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, or revoked key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service or stored object unavailable; hosted beta may not be open",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/activities/{id}": {
      "get": {
        "tags": [
          "Activities"
        ],
        "operationId": "getActivity",
        "summary": "Read activity status",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Activity ID returned by upload",
            "schema": {
              "type": "string",
              "pattern": "^act_[a-f0-9-]{36}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Activity metadata; check status for processing state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Activity"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, or revoked key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown resource or inaccessible workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service or stored object unavailable; hosted beta may not be open",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/activities/{id}/data": {
      "get": {
        "tags": [
          "Activities"
        ],
        "operationId": "getActivityData",
        "summary": "Retrieve decoded JSON",
        "description": "Available only for ready activities. FIT SDK field names and units are retained; source-dependent message fields are intentionally open.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Activity ID returned by upload",
            "schema": {
              "type": "string",
              "pattern": "^act_[a-f0-9-]{36}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Decoded FIT messages",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DecodedActivity"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, or revoked key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown resource or inaccessible workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Data not ready or decoding failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service or stored object unavailable; hosted beta may not be open",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/activities/{id}/original": {
      "get": {
        "tags": [
          "Activities"
        ],
        "operationId": "getOriginal",
        "summary": "Download untouched original",
        "description": "Available even when decoding failed. Compare its SHA-256 with the activity metadata and your source.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Activity ID returned by upload",
            "schema": {
              "type": "string",
              "pattern": "^act_[a-f0-9-]{36}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Exact uploaded FIT bytes",
            "headers": {
              "Content-Disposition": {
                "description": "Attachment with activity-ID filename",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/vnd.ant.fit": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, or revoked key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown resource or inaccessible workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service or stored object unavailable; hosted beta may not be open",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Workspace API key. Keep it in your backend or secret manager; never expose it to browser code."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "Activity": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^act_[a-f0-9-]{36}$"
          },
          "status": {
            "type": "string",
            "enum": [
              "received",
              "queued",
              "ready",
              "failed"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "byte_size": {
            "type": "integer",
            "minimum": 0,
            "maximum": 4194304
          },
          "error_code": {
            "type": "string",
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "links": {
            "type": "object",
            "properties": {
              "self": {
                "type": "string"
              },
              "original": {
                "type": "string"
              },
              "data": {
                "type": "string"
              }
            },
            "required": [
              "self",
              "original",
              "data"
            ]
          }
        },
        "required": [
          "id",
          "status",
          "sha256",
          "byte_size",
          "error_code",
          "created_at",
          "links"
        ]
      },
      "UploadResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Activity"
          },
          {
            "type": "object",
            "properties": {
              "duplicate": {
                "type": "boolean"
              }
            },
            "required": [
              "duplicate"
            ]
          }
        ]
      },
      "ActivityList": {
        "type": "object",
        "properties": {
          "activities": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Activity"
            }
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          },
          "stats": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer",
                "minimum": 0
              },
              "ready": {
                "type": "integer",
                "minimum": 0
              },
              "processing": {
                "type": "integer",
                "minimum": 0
              },
              "failed": {
                "type": "integer",
                "minimum": 0
              },
              "stored_bytes": {
                "type": "integer",
                "minimum": 0
              }
            },
            "required": [
              "total",
              "ready",
              "processing",
              "failed",
              "stored_bytes"
            ]
          }
        },
        "required": [
          "activities",
          "total",
          "limit",
          "offset",
          "stats"
        ]
      },
      "DecodedActivity": {
        "type": "object",
        "properties": {
          "schema_version": {
            "type": "string",
            "enum": [
              "0.1"
            ]
          },
          "parser": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "enum": [
                  "@garmin/fitsdk"
                ]
              },
              "version": {
                "type": "string"
              },
              "fit_profile": {
                "description": "FIT profile version reported by the decoder"
              }
            },
            "required": [
              "name",
              "version",
              "fit_profile"
            ]
          },
          "summary": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "message_count": {
            "type": "integer",
            "minimum": 1
          },
          "messages": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "required": [
          "schema_version",
          "parser",
          "summary",
          "message_count",
          "messages"
        ]
      }
    }
  }
}
