When I try to connect to the preview API using the contentful-management library, I get a 404 when I try to get the environment (master).
Here’s the code:
const contentful = require(“contentful-management”);
const client = contentful.createClient({
host: “preview.contentful.com”,
accessToken: process.env.CONTENTFUL_PREVIEW_TOKEN,
});
const space = await client.getSpace(process.env.CONTENTFUL_SPACE);
// It works OK until this next line where I try to get master. This fails with a 404: The resource could not be found. I also cannot call space.getEnvironments()
const environment = await space.getEnvironment(‘master’);
return environment;
master is our only environment and it is checked by default on the access tokens page:
Any suggestions?