I have set-up a Content-Type which makes use of the UID field, named “slug” (takes its value from a Text field). In the Content Manager view of the Admin Dashboard, the slug shows up and is populated correctly.
When I send a request to the API, it returns all the entries correctly, except for the “slug”, which is null'. I would be very thankful for any pointers on how to address this problem.
Workaround: Edit the generated field in the content manager, save, edit again to restore generated value and save again. Then the value is written to the DB and also returned by the API.
I think, I have the idea how to properly create many slugs without manually updating each of them in content manager, but it’s still a temporary workaround (I use Next.js).
The gist is to update the slug fields through your custom network request (I’m using GraphQL in Strapi). The steps are:
Set permission in Strapi to update the collection, where your slug is, if you haven’t already (Settings → Users & Permissions Plugin → Roles → Public → name of your collection with slugs → check “update”).
Install npm i slufigy
Create an empty page with useEffect hook, to launch the code on page reload
In useEffect, create a function. Inside of if, fetch() your collection to get ids and titles, that we need to slugify (don’t forget to set the pagination limit in GraphQL query, because by default Strapi returns 10 entries max, if I recall correctly).
In .then() statement, create an array with ids and slugified titles.
Then, update the slugs in collection through multiple requests (Strapi doesn’t update entries in batch, so we need to use Promise.all())
I couldn’t figure out how to import or get access to that uid service so I copied the code from that service and included those functions on my custom service. Would be better to import it.