Create a new spreadsheet
Create a new spreadsheet document on your Jspreadsheet Server. 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, the config field must be a single JSON-encoded string. See the HTTP conventions for details.
curl -X POST 'https://sheets.example.com/api/create' \
-H 'Authorization: Bearer <token>' \
-F 'config={"worksheets":[{"worksheetName":"Sheet1","minDimensions":[10,10]}]}'
The same request 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" }
The returned token is the document guid, the identifier used by every other route and by the real-time client to open the document.
Authentication hooks and persistence
Whether the request is allowed is decided by your own authentication hooks; the server passes the Bearer token to beforeConnect and hands the new document to your adapter's create handler for persistence.