I am trying to run an import script with ts-node from npm:
PAYLOAD_CONFIG_PATH=src/payload.config.ts ts-node ./src/scripts/eventImport.ts
But unfortunately i am getting the following error:
APIError: The collection with slug events can't be found
The script is very basic:
const result = await payload.create({
collection: "events",
locale: "nl",
data: {
title: "title",
slug: "slug",
},
});
Does somebody has a suggestion on what is going wrong here?
If you are running this straight from a Node.js file that isn't in any relation to the Express server itself, then you can't use
payload.create
without doing
payload.init
What do you want to achieve?
Payload Local API can be used only inside the Express server (without doing the
payload.init
) (and all the subsequent routes) Payload runs on
ah ok, i am trying to run a one time import script to migrate data from the old CMS to payload
My bad, had to scroll down in the documentation and there it is, a script example...
For future reference:
https://payloadcms.com/docs/local-api/overview#example-script-using-local-apiYeah, if you init Payload first you can use it, forgot to mention 😂
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.