# Controlling Theme Components via API?

**URL:** https://meta.discourse.org/t/controlling-theme-components-via-api/256511
**Category:** Development
**Created:** [February 28, 2023, 4:16pm UTC](https://meta.discourse.org/t/controlling-theme-components-via-api/256511 "2023-02-28T16:16:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kinetiksoft](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kinetiksoft/32/229578_2.png) [@kinetiksoft](https://meta.discourse.org/u/kinetiksoft)
#### Post date: [February 28, 2023, 4:16pm UTC](https://meta.discourse.org/t/controlling-theme-components-via-api/256511/1 "2023-02-28T16:16:06Z")

</div>

Hey everyone,

Just wondering if it’s possible to enable/disable theme components via API. It seems like there was a way to do it, but there is no mention of it in current [Discourse API Documentation](https://docs.discourse.org/). The clue of such possibility was given by ChatGPT, and yeah, I certainly know this is far from a reliable source of information. I just wonder if this is achievable in any remote way, and the fairy tale ChatGPT told me sounds perfect, but doesn’t work. API returns 404 for admin users’s API credentials.

 ![Screenshot 2023-02-28 at 16.15.29@2x](https://global.discourse-cdn.com/meta/original/4X/b/7/4/b74d63cac356673c9996d89cd666e04e6bce9538.png)

> **Asking ChatGPT to refer to the source of it's information on this request**
>
> ![Screenshot 2023-02-28 at 16.15.38@2x](https://global.discourse-cdn.com/meta/original/4X/7/6/c/76cf65c98c840a616da21163f35fa983feca5450.jpeg)

> **ChatGPT apologizes for mistake...**
>
> ![image](https://global.discourse-cdn.com/meta/original/4X/c/1/e/c1e89c0bcd3c15cc97dc974b4efdaa20c64d9e27.jpeg)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 28, 2023, 4:49pm UTC](https://meta.discourse.org/t/controlling-theme-components-via-api/256511/2 "2023-02-28T16:49:49Z")

</div>

My guess is ChatGPT just made it all up. 🤣

So as you can see, we aren’t all out of a job yet. 😛

~~There’s no concept of “enabling” or “disabling” a Theme Component, you simply add or remove it from a parent theme.~~ EDIT: incorrect, see @Canapin’s post below!

ChatGPT ~~made it all up.~~ got the wrong end point and body.

Using the browsers network tab, I can see that adding a Theme Component to a parent theme called a

`PUT /admin/themes/<id>`

(id of component)

With payload something like:

`parent_theme_ids: [<parent_id>]`

I didn’t make that up, I just looked at the Network tab on my browser 🤓

You are welcome

---

<div class="post-metadata">

### Author: ![kinetiksoft](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kinetiksoft/32/229578_2.png) [@kinetiksoft](https://meta.discourse.org/u/kinetiksoft)
#### Post date: [February 28, 2023, 4:54pm UTC](https://meta.discourse.org/t/controlling-theme-components-via-api/256511/3 "2023-02-28T16:54:07Z")

</div>

Sounds like it.

But doesn’t seem to be accessible via external API, though…

Thank you anyway

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 28, 2023, 4:54pm UTC](https://meta.discourse.org/t/controlling-theme-components-via-api/256511/4 "2023-02-28T16:54:57Z")

</div>

That’s from a browser, it must be. Make sure your key has the correct authority (single user, global scope).

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 1, 2023, 11:50pm UTC](https://meta.discourse.org/t/controlling-theme-components-via-api/256511/5 "2023-03-01T23:50:02Z")

</div>

> [@merefield](#):
>
> There’s no concept of “enabling” or “disabling” a Theme Component

The concept exists and the buttons are called “Enable” and “Disable” in Discourse’s interface 🙂

![image](https://global.discourse-cdn.com/meta/original/4X/f/2/a/f2a4cc6dfb971beedfe1d706021825f7c46dbbea.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/d/3/dd39b91186d25af5fe49864e940e4cc9e8446bbe.png)

And it can be done through the API, of course:

> [@Set Theme Dynamically](https://meta.discourse.org/t/set-theme-dynamically/250719/3):
>
> Sorry for the long wait. Busy day technologist So, you can indeed enable or disable a theme or a component with a simple API request. You’ll have to create an API key with the right credentials and assign an admin user to it. in your Discourse: admin panel → API → + New API Key in the script you’ll use, as mentioned, do a PUT request on https://yourdiscourse.com/admin/themes/[id\_theme] with the proper headers (see the authentication part on [https://docs.discourse.org/](https://docs.discourse.org/)) and a JSON body …

I’m talking about both themes AND components in my post but apparently it’s a bit different for themes, so I should fix my solution.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [March 1, 2023, 11:56pm UTC](https://meta.discourse.org/t/controlling-theme-components-via-api/256511/6 "2023-03-01T23:56:46Z")

</div>

Oh! My bad! Well done! 😊 Those buttons are too far down 😉

But ChatGPT still got it wrong 🙂

Amended my post accordingly. @kinetiksoft so sorry, see above, possible but not how ChatGPT was telling you.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 1, 2023, 12:05am UTC](https://meta.discourse.org/t/controlling-theme-components-via-api/256511/8 "2023-04-01T00:05:41Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
