Create tokens with REST API / CLI

I would like to set up a one-click deployment of the nextjs corporate starter, up until the frontend deployment I’m good (provided I handle idempotency of the import), but the frontend requires a manual step of creating tokens in the admin (GitHub - strapi/nextjs-corporate-starter: Strapi Demo application for Corporate Websites using Next.js). What would be the best way to create these tokens programatically? Reading through REST API docs (REST API | Strapi Documentation) I’m not even sure it has the ability to create tokens?

Thank you!

This topic has been created from a Discord post (1217018418465738853) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

Being able to create it using CLI would be even better, I’m creating the super admin using strapi admin:create-user, but there doesn’t seem to be any additional options for creating tokens / affecting the settings through CLI

when it comes to the read-only token, I’m thinking I could insert it to the db directly, the form submission token would be harder

<@960590891200970812> <@874368082431344690> any ideas, please? :pray:

When a token is created through the admin panel, an XHR request is made to the server. Could you check which endpoint that is?

In the end the API tokens qualify as an actual content type, though I don’t believe it has the regular crud operations exposed

So I guess that would be some custom endpoint?

I also looked for for a cli but didn’t find one and used eventually post request to /admin/api-tokens

I tooked the same approach with strapi admin:create-user, logged in (post request to /admin/login) and used the jwt to create a key on /admin/api-tokens

there is no good way to do this right now via the api or seed imports. I created a PR to create deterministic tokens a few weeks ago but it seems to have stalled due to lack of interest.

i am currently solving this problem by creating the tokens externally and writing them directly to the db.

i do the same thing permissions. frankly i have no idea how people manage this in production without a bunch of custom code or messy manual deploys / config