Every call below needs a bearer token from your API key - see the quickstart. Uploading a file answers 402 if your plan does not include Files. File events carry details only, never a link to the file; ask for a download link under your own token.
Each task shows curl, fetch and the SDK (npm i @pickcell/sdk). The SDK examples use one client, made with your API key and account address; it exchanges the key for a token itself:
import { FileShare } from '@pickcell/sdk/fileshare';
const files = new FileShare({
baseUrl: 'https://api.pickcell.io',
apiKey: process.env.PICKCELL_API_KEY,
accountIdentifier: process.env.PICKCELL_ACCOUNT_ADDRESS,
});
Upload a file
Register the document with its hash and type. The response carries an uploadUrl and uploadFields: post every field unchanged, then the bytes as file, as a multipart form straight to storage.
HASH=$(shasum -a 256 invoice-1042.pdf | cut -d' ' -f1)
curl -X POST https://api.pickcell.io/v1/files/documents \
-H "Authorization: Bearer $PICKCELL_TOKEN" \
-H "content-type: application/json" \
-d "{ \"description\": \"Invoice 1042\", \"hash\": \"$HASH\", \"type\": \"PDF\" }"
# Then post to documents.uploadUrl: one -F name=value per uploadFields entry, and -F file=@invoice-1042.pdf last.
import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';
const bytes = await readFile('invoice-1042.pdf');
const hash = createHash('sha256').update(bytes).digest('hex');
const res = await fetch('https://api.pickcell.io/v1/files/documents', {
method: 'POST',
headers: { Authorization: `Bearer ${accessToken}`, 'content-type': 'application/json' },
body: JSON.stringify({ description: 'Invoice 1042', hash, type: 'PDF' }),
});
const { documents: document } = await res.json();
const form = new FormData();
for (const [name, value] of Object.entries(document.uploadFields)) form.append(name, value);
form.append('file', new Blob([bytes]));
await fetch(document.uploadUrl, { method: 'POST', body: form });
import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';
const bytes = await readFile('invoice-1042.pdf');
const hash = createHash('sha256').update(bytes).digest('hex');
const { document, uploadUrl, uploadFields } = await files.documents.create({
description: 'Invoice 1042',
hash,
type: 'PDF',
});
const form = new FormData();
for (const [name, value] of Object.entries(uploadFields!)) form.append(name, value);
form.append('file', new Blob([bytes]));
await fetch(uploadUrl!, { method: 'POST', body: form });
Registering answers 201 with the document under documents. Once the upload is checked against the hash, uploadVerified becomes true and file.stored is sent. A file over 25 MiB is refused by storage.
List your files
curl "https://api.pickcell.io/v1/files/documents?page=1&limit=20" \
-H "Authorization: Bearer $PICKCELL_TOKEN"
const res = await fetch('https://api.pickcell.io/v1/files/documents?page=1&limit=20', {
headers: { Authorization: `Bearer ${accessToken}` },
});
const { documents, pagination } = await res.json();
const { documents, pagination } = await files.documents.list({ page: 1, limit: 20 });
Get a download link
curl https://api.pickcell.io/v1/files/documents/<document id> \
-H "Authorization: Bearer $PICKCELL_TOKEN"
const res = await fetch(`https://api.pickcell.io/v1/files/documents/${documentId}`, {
headers: { Authorization: `Bearer ${accessToken}` },
});
const { documents: document } = await res.json();
const document = await files.documents.get(documentId);
A verified document carries a downloadUrl. For a private file it expires, so read the document again whenever you need one rather than storing it.
Delete a file
curl -X DELETE https://api.pickcell.io/v1/files/documents/<document id> \
-H "Authorization: Bearer $PICKCELL_TOKEN"
await fetch(`https://api.pickcell.io/v1/files/documents/${documentId}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${accessToken}` },
});
await files.documents.delete(documentId);
The answer is always 204, even for a file that is already gone, so a retried delete is safe.