Create a new spreadsheet

The configuration accepts the same options as the Jspreadsheet client: worksheets, dimensions, columns, formulas and so on.

Request

POST /api/create with a Bearer token. Unlike the other write routes, config must be a single JSON-encoded string (see HTTP conventions).

curl -X POST 'https://sheets.example.com/api/create' \
  -H 'Authorization: Bearer <token>' \
  -F 'config={"worksheets":[{"worksheetName":"Sheet1","minDimensions":[10,10]}]}'

With fetch:

const baseUrl = 'https://sheets.example.com/api';
const token = '[Your access token]';
const headers = { 'Authorization': `Bearer ${token}` };

const config = {
    worksheets: [
        {
            worksheetName: 'Sheet1',
            minDimensions: [10, 10],
        }
    ]
};

const result = await (await fetch(`${baseUrl}/create`, {
    method: 'POST',
    headers,
    body: new URLSearchParams({ config: JSON.stringify(config) }),
})).json();

// The new document guid
console.log(result.token);

Response and document guid

{ "success": 1, "token": "5c609bcc-1b79-48a8-8f2c-5b89572c7d6f" }

token is the document guid, used by every other route and by the real-time client to open the document.

Authentication hooks and persistence

Your authentication hooks decide whether the request is allowed: the Bearer token goes to beforeConnect, and the new document goes to your adapter's create handler for persistence.