Search code examples
content-management-systemstrapi

How to change the API ID in strapi?


I just started working on strapi. After created some collections, I want to go back and change the API id.

API ID field is disabled

But it seems that I cannot do that in the content-type builder.

If I need to change it, do I have to delete the whole collection and then start from scratch again? Or is it possible to change some configuration to handle it?

I went through the documentations and also google. Cant find anything on the topic. I guess it may be possible to dig into the JavaScript and write my own API. but it doesn't make much sense to do that for such simple change.


Solution

  • It is not simple but it is possible. In the API folder, you need to locate the folder that contains the collection you want to change. In your example, it will be /api/our-services-card.

    Let's suppose you want to change it to our-service-card.

    You will need to rename /api/our-services-car to /api/our-service-card. You will also need to rename our-services-card folder that will be inside of /api/our-service-card/content-types.

    Then, you must change the schemas.json file contained in this last folder:

    "kind": "collectionType",
    "collectionName": "our-service-cards",
    "info": {
      "singularName": "our-service-card",
      "pluralName": "our-service-cards",
      "displayName": "Service Card",
      "description": ""
    }
    

    Then, check rest of the folders to see if there are any reference to the old name. Restart strapi and that should work (it works for me).