Repository navigation
Expand file tree
/
Copy pathexample.js
More file actions
63 lines (54 loc) 路 1.76 KB
/
Copy pathexample.js
File metadata and controls
63 lines (54 loc) 路 1.76 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { AnytypeClient } from './index.js';
// Example usage of the Anytype API JavaScript client
async function main() {
// Initialize the client
const client = new AnytypeClient({
BASE: 'https://api.anytype.io',
HEADERS: {
'Authorization': 'Bearer YOUR_API_KEY_HERE'
}
});
try {
// List all spaces
console.log('Fetching spaces...');
const spaces = await client.spaces.listSpaces();
console.log('Spaces:', spaces);
if (spaces.data && spaces.data.length > 0) {
const spaceId = spaces.data[0].id;
// List objects in the first space
console.log('\nFetching objects from space:', spaceId);
const objects = await client.objects.listObjects(spaceId);
console.log('Objects:', objects);
// Create a new object
console.log('\nCreating new object...');
const newObject = await client.objects.createObject(spaceId, {
type_key: 'page',
name: 'Test Page from JS Client',
body: 'This page was created using the JavaScript API client'
});
console.log('Created object:', newObject);
// Update the object
console.log('\nUpdating object...');
const updatedObject = await client.objects.updateObject(
spaceId,
newObject.object.id,
{
name: 'Updated Test Page',
body: 'This content has been updated'
}
);
console.log('Updated object:', updatedObject);
// Search for objects
console.log('\nSearching for objects...');
const searchResults = await client.search.searchSpace(spaceId, {
query: 'Test',
limit: 10
});
console.log('Search results:', searchResults);
}
} catch (error) {
console.error('Error:', error);
}
}
// Run the example
main();