This article is for the latest version of the Flatfile Data Exchange Platform.
You may run into circumstances where you want to update a sheet to be readonly after it has been created, rather than creating the sheet in a readonly state to begin with. Updating sheets after they have been created is something that need to be done using the api.workbooks.update
endpoint, rather than using one of our sheets endpoints.
Here's an example of how this could be done after a file has been mapped and imported to your sheet.
//set sheet to readonly after mapping is completed
export default function (listener) {
listener.on("job:completed", { job: "workbook:map" }, async (event) => {
const { jobId } = event.context;
const workbook = await api.workbooks.get(event.context.workbookId);
const response = await api.workbooks.update(event.context.workbookId, {
name: workbook.data.name,
sheets: workbook.data.sheets.map((sheet) => ({
slug: sheet.config.slug,
name: sheet.config.name,
fields: [...sheet.config.fields],
actions: sheet.config.actions ?? [],
//setting the access to an empty array makes the sheet readonly
access: [],
})),
actions: workbook.data.actions,
});
console.log(response);
});
}
Note: In this example since we are setting this to run after a job has already completed, we are not going to acknowledge or set the job to complete, since that has already happened.