/
Contentful Project Configuration
Contentful Project Configuration
Configuration Steps
Retrieve Contentful API keys from the UI.
CONTENTFUL_SPACE_ID="YOUR_SPACE_ID" CONTENTFUL_ACCESS_TOKEN="YOUR_CONTENTFUL_CONTENT_DELIVERY_API_KEY"
Implement the API Keys in project.
This code sample shows the connection to Contentful’s GraphQL API, and how we can access the our space by providing those API keys.
async function fetchGraphQL(query, preview = false) { return fetch( `https://graphql.contentful.com/content/v1/spaces/${process.env.CONTENTFUL_SPACE_ID}`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${ preview ? process.env.CONTENTFUL_PREVIEW_ACCESS_TOKEN : process.env.CONTENTFUL_ACCESS_TOKEN }`, }, body: JSON.stringify({ query }), } ).then((response) => response.json()); }
Once we have a GraphQL connection to Contentful, we can access various entries by querying that source.
//Example GraphQL Query for Post types export async function getAllPostsForHome(preview) { const entries = await fetchGraphQL( `query { postCollection(order: date_DESC, preview: ${preview ? "true" : "false"}) { items { ${POST_GRAPHQL_FIELDS} } } }`, preview ); return extractPostEntries(entries); }
After we grab what content we need, we can then render the payload to the page.
Example of a ReactJS/NextJS component that has a connection to Contentful
, multiple selections available,
Related content
Architecture Overview
Architecture Overview
Read with this
Jamstack: A Website Architecture
Jamstack: A Website Architecture
More like this
Creating a content type via migration scripts & Contentful CLI
Creating a content type via migration scripts & Contentful CLI
Read with this
Getting Started
Getting Started
More like this
Client Catalog Reference Model V1 (Currently Updating)
Client Catalog Reference Model V1 (Currently Updating)
Read with this
Publication Content Type v1
Publication Content Type v1
More like this
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'html-macro' is unknown.