harbor0APIBeta

Beta. The harbor0 API is still in beta, so routes and responses may change before it is final. What beta means

Quickstart

This page takes you from nothing to uploading and downloading a file with curl. It assumes your account does not use end-to-end encryption. If it does, read this page for the flow and then follow Uploading to an encrypted account, because names and contents must be encrypted on your side.

1. Create a token

  1. Open app.harbor0.com and go to Settings.
  2. In the harbor0 API card, choose Create API key.
  3. Give it a name you will recognise later (for example "Backup script"), pick Read and write or Read-only, and choose when it expires.
  4. Copy the token. It starts with h0_pat_ and is shown only once.

Keep it in an environment variable rather than in your code:

export HARBOR0_TOKEN='h0_pat_...'

2. Check who you are

curl -s https://api.harbor0.com/v1/users/me \
  -H "Authorization: Bearer $HARBOR0_TOKEN"

The response describes your account and storage:

{
  "user": { "id": "…", "email": "you@example.com", "displayName": "…", "storageQuotaBytes": 214748364800, "…": "…" },
  "storage": { "quotaBytes": 214748364800, "usedBytes": 1048576, "reservedBytes": 0, "availableBytes": 214747316224 }
}

If user.e2ee is present, the account is end-to-end encrypted. Continue with the encryption guides.

3. List your top folder

The top of My Drive has the folder ID root:

curl -s "https://api.harbor0.com/v1/drive/folders/root/children?limit=100" \
  -H "Authorization: Bearer $HARBOR0_TOKEN"
{
  "items": [
    { "id": "9b7…", "type": "FOLDER", "name": "Taxes", "parentId": null, "revision": 1, "…": "…" },
    { "id": "c41…", "type": "FILE", "name": "notes.txt", "sizeBytes": 812, "contentHash": "5e8…", "…": "…" }
  ],
  "nextCursor": null
}

4. Upload a file

Uploads go straight to storage in parts, in three steps: create the upload, send the bytes to the signed URLs it gives you, then complete it. A small file is a single part.

FILE=notes.txt
SIZE=$(wc -c < "$FILE" | tr -d ' ')
SHA=$(shasum -a 256 "$FILE" | cut -d' ' -f1)

# a) Create the upload (operationId is any new UUID).
UPLOAD=$(curl -s https://api.harbor0.com/v1/uploads \
  -H "Authorization: Bearer $HARBOR0_TOKEN" -H 'Content-Type: application/json' \
  -d "{\"operationId\":\"$(uuidgen)\",\"parentId\":null,\"name\":\"$FILE\",\"sizeBytes\":$SIZE,\"contentHash\":\"$SHA\"}" \
  | jq -r .upload.id)

# b) Get a signed URL for part 1 and PUT the bytes there.
URL=$(curl -s https://api.harbor0.com/v1/uploads/$UPLOAD/parts \
  -H "Authorization: Bearer $HARBOR0_TOKEN" -H 'Content-Type: application/json' \
  -d '{"partNumbers":[1]}' | jq -r '.parts[0].uploadUrl')
ETAG=$(curl -s -X PUT --data-binary @"$FILE" "$URL" -D - -o /dev/null \
  | awk 'tolower($1)=="etag:" {print $2}' | tr -d '\r')

# c) Complete it with the part's ETag and the file's SHA-256.
curl -s https://api.harbor0.com/v1/uploads/$UPLOAD/complete \
  -H "Authorization: Bearer $HARBOR0_TOKEN" -H 'Content-Type: application/json' \
  -d "{\"parts\":[{\"partNumber\":1,\"etag\":$ETAG}],\"contentHash\":\"$SHA\"}"

The last call returns the new file as item. Files larger than one part (64 MiB or more) are covered in Uploading files.

5. Download it again

Ask for a short-lived download link, then fetch it. The link is a signed storage URL, so it needs no Authorization header:

ITEM=c41...   # the item's id
LINK=$(curl -s https://api.harbor0.com/v1/downloads \
  -H "Authorization: Bearer $HARBOR0_TOKEN" -H 'Content-Type: application/json' \
  -d "{\"driveItemId\":\"$ITEM\"}" | jq -r .downloadUrl)
curl -s -o downloaded.txt "$LINK"

Next steps

  • Read Requests and responses for operation IDs, revisions and paging, which every write uses.
  • Use the ready-made clients in Complete examples. They work on both encrypted and unencrypted accounts.