How to use REST v2 API to change Active Theme

0

Hi All

I want to set a diffrent theme as active theme using Japer REST v2 api.

I'm able to get my theme/resource using this endpoint 

http://<host>:<port>/jasperserver[-pro]/rest_v2/resources/themes/my_theme

What I want is to change active default theme to my theme.

Thank you

Thato's picture
4
Joined: Mar 29 2018 - 3:32am
Last seen: 1 month 1 week ago

2 Answers:

0

Hi Thato
You utilizing Community Edition or Pro as the rest request stucture changes. 
So the manual gives example, but is focused on Jasper Pro and assuming you have already created an org called "Audit"
The example is 
PUT http://localhost:8080/jasperserver-pro/rest_v2/organizations/Audit
Payload will have content type : application/json
With json payload being :
{"theme":"jasper_dark"}

But i'll look into and test out how to do this in CE. As "organizations" do not work the same in CE.
;-)

joseng62's picture
620
Joined: Dec 5 2014 - 2:43am
Last seen: 1 month 1 week ago
0

Ok here we go.
The REST api call mentioned in documentation is for pro only. 

So this could be a work around. 

Do a GET request with jasper url and add flow.html?_flowId=searchFlow to the url. 

Example http://localhost:8081/jasperserver/flow.html?_flowId=searchFlow

Then in the Body you receive back, you need to look for __jrsConfigs__.flowExecutionKey = YOU_NEEd_THIS_VALUE; in the body.

  • Note the value flowExecution key will change from time to time, depending on how long the time lapse it between requests, change in users etc.

Next you need to do a POST request.

 

Here is example of POST message : 

url: http://localhost:8081/jasperserver/flow.html?_flowExecutionKey=THE_ABOVE_Key_Value &_eventId=setActiveTheme

 

Headers: 

X-REMOTE-DOMAIN : 1

Content-Type : application/x-www-form-urlencoded

 

BODY: (Form)

folderUri=/themes/jasper_dark

 

⌂⌂⌂⌂

I tested the above REST call multiple time, I just updated the folderUri and the execution Key from time to time. All worked and I received a 200 response. 

 

Side note for manual testing, another way to get hold of the execution key is via the developer console. 

After signing into Jasper. 

Use Console tab and run: 

__jrsConfigs__.flowExecutionKey

this should return the code for you.

joseng62's picture
620
Joined: Dec 5 2014 - 2:43am
Last seen: 1 month 1 week ago
Feedback