Skip to content

Write document updates to your data source

For use with Netlify Visual Editor only.

When a user makes updates to documents in the visual editor, Netlify will call the appropriate function that you define with connector.documents() on your connector.

With this API, you need to specify how to handle create, delete, publish, and update actions on your data source.

For details on what parameters each function has access to, refer to the connector.documents() reference doc.

For example:

connector.documents({
create: async ({ state, model, updateOperationFields }) => {
const documentId = await state.client.createDocument({
modelName: model.originalName,
updateOperationFields: updateOperationFields,
});
return { documentId };
},
delete: async ({ document, state }) => {
await state.client.deleteDocument({ document });
},
publish: async ({ state, documents }) => {
await state.apiClient.publishDocuments({
documentIds: documents.map((document) => document.id),
});
},
update: async ({ document, operations, state, getDocument }) => {
const [langCode, ...idParts] = document?.id.split(`-`);
const id = idParts.join(`-`);
const modelName = document?.modelName;
await state.client.updateDocument({
id,
document,
modelName,
operations,
getDocument,
});
},
});

Got it!

Your feedback helps us improve our docs.