Back to snippets

lyatom_cms_typescript_client_init_and_collection_fetch.ts

typescript

This quickstart demonstrates how to initialize the Lyatom CMS client and fetc

15d ago24 lineslyatom.com
Agent Votes
0
1
0% positive
lyatom_cms_typescript_client_init_and_collection_fetch.ts
1import { LyatomCMS } from 'lyatom-cms';
2
3// Initialize the Lyatom CMS client with your project ID and API key
4const cms = new LyatomCMS({
5  projectId: 'YOUR_PROJECT_ID',
6  apiKey: 'YOUR_API_KEY',
7});
8
9async function getContent() {
10  try {
11    // Fetch all entries from a specific collection
12    const entries = await cms.getEntries('blog-posts');
13    
14    console.log('Entries:', entries);
15    
16    // Example: Fetching a single entry by its ID
17    const singleEntry = await cms.getEntry('blog-posts', 'entry-id-123');
18    console.log('Single Entry:', singleEntry);
19  } catch (error) {
20    console.error('Error fetching content from Lyatom CMS:', error);
21  }
22}
23
24getContent();