Managing site customization via API

Hey guys, I was wondering if there is a way of managing CSS/HTML customization via API. This means to fetch/update items here: admin/customize/css_html/

I’ve read this and didn’t had too much luck:

  • GETting this in POSTMAN {{base_url}}/admin/site_customizations/22?api_key={{api_key}}&api_username={{api_username}} returns nothing;
  • GETting this in POSTMAN {{base_url}}/admin/site_customizations/ will return Oops! That page doesn’t exist or is private.

Thanks!

Are you using the system api key?

Yeah, i did, but now i tried with an (admin) user API key and still not working.

1 Like

devtools says this is working:

curl 'https://meta.discourse.org/admin/site_customizations'

My guess is you have issues with your api keys or something.

1 Like

I feel dumb today :smiley: Can you please give me a full curl sample?

My Postman cURL looks like this

curl -X GET 
-H "Cache-Control: no-cache" -H "Postman-Token: xxx" 
"https://my-site/admin/site_customizations/?api_key=my-api-taken-from-my-user-admin-page&api_username=my-username"

And the response looks like this:

(The username has administrator rights)


If i use postman to make a request that requires auth, it works:

{{base_url}}/admin/users/list/suspended.json?api_key={{api_key}}&api_username={{api_username}}

Works just fine.

My guess is that the controller is checking for XHR, maybe try adding:

x-requested-with:XMLHttpRequest

4 Likes

That was it! Thanks! (mark as solved? :D)

1 Like