After adding a new story with storyblok-js-client, whey are fields empty instead of using the default values?

I’m adding new stories using storyblok-js-client. When I use the storyblok-js-client post method to add a new story, it seems that the fields are not being populated with the default field values (as defined in component settings).
The expected result is when I add a new story via the storyblok-js-client post method, that the field values are set to the default values. Is there a way to make that happen?

For example, I have a required field named “paddingTop” with a default value of “standard”. After adding a post with storyblok-js-client, I’m expecting the value of “paddingTop” to be “standard”. Instead, the value is blank.

May not have anything to do with it, but I’m using components from a different workspace.

Hello @edtalmadge,

these standard values are only used when you’re using the UI for creating stories.

When you use the Management API with or without the JS client you need to pass these values in the payload.

What you could do is to check the schema () of a content type for a possible default value and add this then when it exists with a logic to the story’s payload when you didn’t pass anything in that field.
Here is an example schema:

{
    "name": "defaultvalue",
    "display_name": null,
    "created_at": "2022-02-24T11:24:40.133Z",
    "updated_at": "2022-02-24T11:24:55.705Z",
    "id": 2221810,
    "schema": {
        "example": {
            "type": "text",
            "default_value": "test"
        }
    },
    "image": null,
    "preview_field": null,
    "is_root": true,
    "preview_tmpl": null,
    "is_nestable": false,
    "all_presets": [],
    "preset_id": null,
    "real_name": "defaultvalue",
    "component_group_uuid": null,
    "color": null,
    "icon": null
}

Best regards
Hannes

1 Like

Great tip, thanks @Hannes

1 Like