Get the "custom settings" with Content / Admin API

I would like to receive the custom settings via the Content API or the Admin API. Is that possible?
But I have not found an endpoint. I thought it was settings.

One option if you can edit the theme would be to make a page template that writes out the values you want. There might well be an endpoint, but that’s a workaround if there isn’t.

1 Like

You’re full of good ideas, Cathy.
I would never have thought of that, thank you.
I will create a page with the slug “custom_settings” with the ones I need.

The admin API exposes them via /ghost/api/admin/custom_theme_settings/, but it’s not available for token-based authentication

1 Like

Many thanks for the hint.
This means that only “user authentication” is an option.
It’s not ideal for using Ghost as a headless CMS.
I will try Cathy’s suggestion first.
On the other hand, there is still direct access to the database in the backend :slight_smile:

At the same time, headless Ghost implies you won’t be using the native ghost theme layer, so custom settings “isn’t needed”.

But I can see some benefits of doing this, like allowing staff to have a UI to make some minor changes instead of editing the headless code

That’s the point, it’s more flexible.

I have made it with Cathy’s suggestion:

  1. custom-settings.hbs
{
    "header_style": "{{@custom.header_style}}",
    "body_font": "{{@custom.body_font}}",
    "header_and_footer_color": "{{@custom.header_and_footer_color}}",
    "post_feed_style": "{{@custom.post_feed_style}}"
}
  1. routes.yaml
routes:
  /custom-settings/:
    template: custom-settings
    content_type: application/json

collections:
  /:
   ...

On the clientside I use fetch, not the GhostContentAPI:

export async function getCustomSettings() {
   return await fetch(`${API_URL}/custom-settings/`).then(async (res) => {
        const obj = await res.text()
        return JSON.parse(obj)
    }).catch(error => {
        console.error("getCustomSettings error:", error);
    })
}

That’s all.
You can use like:

const customSettings = await getCustomSettings()
console.log('customSettings', customSettings, customSettings.body_font, ....)


1 Like