You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Create a document in a dataset in Sanity. [See the documentation](https://www.sanity.io/docs/http-reference/actions)",
8
+
version: "0.0.1",
9
+
type: "action",
10
+
annotations: {
11
+
destructiveHint: false,
12
+
openWorldHint: true,
13
+
readOnlyHint: false,
14
+
},
15
+
props: {
16
+
sanity,
17
+
dataset: {
18
+
propDefinition: [
19
+
sanity,
20
+
"dataset",
21
+
],
22
+
},
23
+
documentId: {
24
+
type: "string",
25
+
label: "Document ID",
26
+
description: "A unique identifier for the document to create",
27
+
},
28
+
type: {
29
+
type: "string",
30
+
label: "Type",
31
+
description: "The type of document to create. Example: `post`",
32
+
},
33
+
additionalFields: {
34
+
type: "object",
35
+
label: "Additional Fields",
36
+
description: "Additional fields to add to the document. Example: `{\"title\":\"My First Post\",\"slug\":{\"current\":\"my-first-post\"},\"body\":[{\"_type\":\"block\",\"children\":[{\"_type\":\"span\",\"text\":\"Hello world!\"}]}]}`",
37
+
optional: true,
38
+
},
39
+
},
40
+
asyncrun({ $ }){
41
+
constresponse=awaitthis.sanity.createDocument({
42
+
$,
43
+
dataset: this.dataset,
44
+
data: {
45
+
actions: [
46
+
{
47
+
actionType: "sanity.action.document.create",
48
+
publishedId: this.documentId,
49
+
document: {
50
+
_id: `drafts.${this.documentId}`,
51
+
_type: this.type,
52
+
...parseObject(this.additionalFields),
53
+
},
54
+
},
55
+
],
56
+
},
57
+
});
58
+
59
+
$.export("$summary","Successfully created document");
0 commit comments