Content Types and pages

Hi,

I have two questions related to content-types and pages.

  1. How to change the content-type of an existing page? is this even possible?
    1.1) If i edit the schema in one page of a whole category, how to make this available/consistent to all sibling pages?
  2. If I edit the schema (content/structure/naming) of a component that acts as content-type, why are deleted/edited fields still exists in the json? e.g. change schema filed from “Foo” to “foo” or “Bar” all of them will outputted in the json?

I asked myself how should I develop/change a proper structure if old schema structures keep still existing and pages couldn’t reieve a new content-type after they a created?

Hello @chartier,

to 1. It is possible to change the type of a page with the help of the management API. For this, you need to fetch the story https://www.storyblok.com/docs/api/management#core-resources/stories/retrieve-one-story and then you can change the story object. The attribute of interest is component directly in the content-type:

    "content": {
      "_uid": "98cccd01-f807-4494-996d-c6b0de2045a5",
      "component": "your_content_type"
      // and fields you define yourself are in here
    },

After modifying that you can update the existing story with the request shown here https://www.storyblok.com/docs/api/management#core-resources/stories/update-story

To 1.1 + 2. When you modify the schema of a content type you need to add the new field(s) to existing stories using the management API as changing the schema doesn’t change existing content for the fact that this could break your existing implementation.
When you remove fields from the schema then you will see a note at the end of the content view inside of a story:


Clicking on that will open a submenu with more details and the option to remove all or to read them:

It is also possible to clean the stories from out of schema items using a custom script. My colleague provided an example of how this could look like: https://gist.github.com/onefriendaday/5397227c951538d90a993c6592f7fb1a

Best regards
Hannes