tipe docs
Home

Fetching Content

Create Client

Our Content API allows you to fetch content from your Tipe projects. We'll use the js client to interact with the Content API. This package works on browsers and node.js.First, initialize the Tipe js client if you don't have one already by using a framework integration.

import {createTipeClient} from '@tipe/js'
const tipe = createTipeClient({
projectId: 'YOUR-TIPE-PROJECT-ID',
environment: 'Production'
})

If your Tipe environment is private or you want to query for draft content, you'll need an API KEY. We don't recommend using private environments on the client of web apps as your API KEY will be vulnerable. Using a framework like Next.js that has server-side data fetching or calling Tipe from your own server is preferred.

Query for documents

Using the Tipe client, we can now query for a list of documents.

import {createTipeClient} from '@tipe/js'
const tipe = createTipeClient({
projectId: 'YOUR-TIPE-PROJECT-ID',
environment: 'Production'
})
(async () => {
const { documents } = await tipe.getDocuments({type: 'blogPost'})
})()

This query will find all documents that are type blogPost. The return value is a pagination object. Documents will be an array of your documents.

// documents
[
{
"published": true,
"hasPublished": true,
"name": "Top 10 Games 2020",
"type": "blogPost",
"environment": {
"id": "5f39dedcb7b405002c3681dd",
"name": "Production"
},
"project": {
"name": "Home Site",
"createdAt": "2020-08-17T01:35:25.473Z",
"id": "5f39dedcb7b405002c3681dc"
},
"fields": {
"title": "do some more stuff here",
//.. other fields
},
"createdBy": {
"firstName": "Zhana",
"lastName": "Milly"
},
"createdAt": "2020-09-04T17:27:47.148Z",
"updatedAt": "2020-09-04T17:27:47.177Z",
"id": "ckdxv1sep000018tg39di3335",
"status": "PUBLISHED"
},
// ... more documents
]

You can also query for just one document.

import {createTipeClient} from '@tipe/js'
const tipe = createTipeClient({
projectId: 'YOUR-TIPE-PROJECT-ID',
environment: 'Production'
})
(async () => {
// document list
const { documents } = await tipe.getDocuments({type: 'blogPost'})
// one document
const document = await tipe.getDocument({id: 'YOUR-DOCUMENT-ID'})
})()

Filtering

You can filter the content API by types and field values to find what you need.