createDocument
The createDocument method is responsible for creating a document in the underlying content source.
Netlify Create calls this method when the user creates a new documents using the Netlify Create UI.
Parameters
This method receives an options
object with the following properties:
updateOperationFields: Record<string, UpdateOperationField>
: A map of update operation fields by field names. Please introspect theUpdateOperationField
in the@stackbit/types
package for more information.model: Model
: A model representing the document to be created.locale?: string
: A locale id for the document to be created.userContext?: UserContext
: An object that contains the user'semail
,name
, and optional OAuth access tokens defined by theUserContext
generic type.
Return Value
This method should return a Promise
that resolves with an object containing the following properties:
documentId: string
: The ID of the created document.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
The convertOperationFieldsToAPIDocument
is an example of a utility method that takes an array of Netlify Create update operation fields and converts them to the format expected by the content source API.