Max Schmitt

August 17 2023

Contentful: How to Find Unused Types

Contentful is a great option if you need a free headless CMS that's easy to setup.

On the free plan, Contentful limits you to 25 content types. If you use those up, you need to pay 350$ per month to unlock more content types – a pretty expensive upgrade for small websites.

So before upgrading, you might want to check if you have any unused types that you could remove from your project.

You can do so using the following script:

unused-contentful-types.js

const { createClient } = require('contentful')
const CONTENTFUL_ACCESS_TOKEN = '...' // Insert your access token here
const CONTENTFUL_SPACE_ID = '...' // Insert your space ID here
const client = createClient({
space: CONTENTFUL_SPACE_ID,
accessToken: CONTENTFUL_ACCESS_TOKEN,
})
;(async () => {
const contentTypes = await client.getContentTypes().then((result) => result.items)
for (const contentType of contentTypes) {
const entries = await client.getEntries({ content_type: contentType.sys.id }).then((result) => result.items)
console.log(entries.length, 'entries:', contentType.sys.id)
}
})()

You can run it like this:

$ node unused-contentful-types.js
0 entries: blogArticle
0 entries: blogNews
0 entries: blogTutorial
1 entries: blogInterview
1 entries: blogReview
1 entries: blogGuide
1 entries: blogEvent
1 entries: blogPodcast
2 entries: blogVideo
3 entries: blogPhotostory
4 entries: blogQuote
5 entries: blogInfographic
6 entries: blogInteractive
6 entries: blogPoll
7 entries: blogSlideshow
8 entries: blogQuiz
9 entries: blogListicle
11 entries: blogRecipe
12 entries: blogPersonalStory
14 entries: blogAnalysis
25 entries: blogOpinion
30 entries: blogTravelogue
32 entries: blogResearch
36 entries: blogResource
44 entries: blogShowcase