Closed Kmancoop closed 1 year ago
I'm having the same issue. Do you got any results?
@Kmancoop @Aeziren FYI small modification in setup.ts
solves the issue.
all these variables:
const spaceId = await prompt(PROMPTS.spaceId);
const deliveryToken = await prompt(PROMPTS.deliveryToken);
const managementToken = await prompt(PROMPTS.managementToken);
are treated later as a string, while they are objects.
Long story short here is working script that you can use
// bin/setup.ts
import spaceImport from 'contentful-import';
import { prompt } from 'enquirer';
import chalk from 'chalk';
import os from 'os';
import path from 'path';
import { writeFileSync, readFileSync } from 'fs';
const ROOT_PATH = path.resolve();
const CONFIG_FILE_PATH = path.resolve(ROOT_PATH, '.env');
const CONFIG_PATH = path.resolve(ROOT_PATH, 'bin', 'contentful-config.json');
const MESSAGES = {
welcome: `
To set up this project you need to provide your Space ID
and the belonging API access tokens.
You can find all the needed information in your Contentful space under:
${chalk.yellow(
`app.contentful.com ${chalk.red('->')} Space Settings ${chalk.red(
'->',
)} API keys`,
)}
The ${chalk.green('Content Management API Token')}
will be used to import and write data to your space.
The ${chalk.green('Content Delivery API Token')}
will be used to ship published production-ready content in your Gatsby app.
The ${chalk.green('Content Preview API Token')}
will be used to show not published data in your development environment.
Ready? Let's do it! 🎉
`,
env: 'Writing config file...',
importing: 'Importing content into your Contentful ...',
done: `
All set! You can now run:
${chalk.yellow('yarn start')}
to see it in action.`,
};
const PROMPTS = {
spaceId: {
type: 'input',
name: 'spaceId',
message: 'Your Space ID',
},
deliveryToken: {
type: 'password',
name: 'deliveryToken',
message: 'Your Content Delivery API access token',
},
managementToken: {
type: 'password',
name: 'managementToken',
message: 'Your Content Management API access token',
},
};
export const setup = async () => {
console.log(MESSAGES.welcome);
const spaceId = await prompt(PROMPTS.spaceId);
const deliveryToken = await prompt(PROMPTS.deliveryToken); // changed
const managementToken = await prompt(PROMPTS.managementToken); // changed
console.log(MESSAGES.env);
const envData = [`SPACE_ID=${spaceId.spaceId}`, `ACCESS_TOKEN=${deliveryToken.deliveryToken}`];
writeFileSync(CONFIG_FILE_PATH, envData.join(os.EOL));
console.log(MESSAGES.importing);
const content = JSON.parse(readFileSync(CONFIG_PATH, 'utf-8'));
await spaceImport({ spaceId:spaceId.spaceId, managementToken:managementToken.managementToken, content }); // changed
console.log(MESSAGES.done);
};
setup();
https://github.com/EmaSuriano/gatsby-starter-mate/pull/896 solves the issue @EmaSuriano do you mind merge this pr? 👀
Should be fixed with the #896 by @rythm-of-the-red-man :)
Hey! I might be confused about what to do here, but I'm currently having an issue in the run after the access tokens are provided, when the config file is importing content. I'm only getting this far through the process before this error message appears:
✔ Validating content-file ✔ Initialize client (1s) ✖ Checking if destination space already has any content and retrieving it (1s) → NotFound: Status: 404 - Not Found - Message: The resource could not be found. - Request ID: 622c53c8-33bf-4e05-80d3-c2f821441e24
Not sure what to do here, as to my knowledge the contentful tokens are correct and the contentful space is blank.
Let me know if any more issue might help deduce a solution.