Create document in AppWrite
1
import * as sdk from "https://deno.land/x/[email protected]/mod.ts";
2
import type { Resource } from "https://deno.land/x/[email protected]/mod.ts";
3
4
export async function main(
5
auth: Resource<"appwrite">,
6
collectionId: string,
7
databaseId: string,
8
data: object,
9
documentId?: string
10
)
11
{
12
13
let client = new sdk.Client();
14
client
15
.setEndpoint(auth.endpoint) // Your API Endpoint
16
.setProject(auth.project) // Your project ID
17
.setKey(auth.key) // Your secret API key
18
19
const databases = new sdk.Databases(client);
20
21
return await databases.createDocument
22
(
23
databaseId,
24
collectionId,
25
documentId? documentId : sdk.ID.unique(),
26
data
27
28
29
}
30