Last active
April 9, 2021 08:36
-
-
Save colinappnovation/315f9e302b7b82c8259d70a2cce3de97 to your computer and use it in GitHub Desktop.
Get all Content Types from Contentful for all Spaces which executer has access to
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contentful = require("contentful-management"); | |
const fs = require("fs"); | |
require("dotenv").config(); | |
const { CONTENTFUL_MANAGEMENT_TOKEN } = process.env; | |
const client = contentful.createClient({ | |
accessToken: CONTENTFUL_MANAGEMENT_TOKEN, | |
}); | |
(async () => { | |
const spaces = await client.getSpaces(); | |
async function getContentTypes(spaceId = "") { | |
const space = await client.getSpace(spaceId); | |
const env = await space.getEnvironment("master"); | |
return await env.getContentTypes(); | |
} | |
const entries = await Promise.all( | |
spaces.items.map(async (s) => { | |
const { | |
name, | |
sys: { id }, | |
} = s; | |
const spaceTypes = await getContentTypes(id); | |
return { name, contentTypes: spaceTypes.items }; | |
}) | |
); | |
fs.writeFileSync( | |
"all-space-content-types.json", | |
JSON.stringify(entries, null, 4) | |
); | |
console.log("All done!"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment