Managing site customization via API


(Ionuț Staicu) #1

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!


(Jay Pfaffman) #2

Are you using the system api key?


(Ionuț Staicu) #3

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


(Sam Saffron) #4

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.


(Ionuț Staicu) #5

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.


(Sam Saffron) #6

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

x-requested-with:XMLHttpRequest


(Ionuț Staicu) #7

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