I need to access json data that is stored in a Confluence page and use this in Scriptrunner for Jira cloud as a json map.
When I try to access the api endpoint of Confluence for the page, I get 'unauthorized'.
I tried both possible settings: run script as scriptrunner user and tried it as my own user.
Same result for both cases.
I can't use a normal request as on datacenter with authentication setup. this is predefined in Scriptrunner for cloud, by the setting above (Scriptrunner Add-on user or current user)
How can I access this json data in Confluence or get authenticated using a service user?
Hi @Janco Hoekstra ,
Thank you for your question.
Have you tried to specify the basic authorization?
From Scriptrunner for Jira Cloud it could be used the following piece of script to read a Confluence page:
def pageBody = get("https://<mysite>.atlassian.net/wiki/rest/api/content/<page_id>?expand=body.view")
.basicAuth(USER_SERVICE_EMAIL, USER_TOKEN)
.asString()
.getBody()
The key is to specify the .basicAuth function with email and token variable.
In this case it returns an html, so it is required to parse the pageBody variable in order to get the page content required.
You can use the v2 api with this method: https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-id-get
Another option is what described in the following tutorial from Scriptrunner here: https://www.scriptrunnerhq.com/help/example-scripts/create-confluence-page-for-issues-cloud (please keep attention in the "Good to know" section that specify: "This snippet requires that you have both ScriptRunner for Jira Cloud and ScriptRunner for Confluence Cloud installed. If you do not have ScriptRunner for Confluence Cloud installed, you will need to update this example to specify user credentials to access the Confluence instance."
I suggest to use a service account, as referenced here: https://support.atlassian.com/user-management/docs/understand-service-accounts/
I hope it helps and please flag the reply if useful.
Kind regards
Thanks Matteo,
This works perfect! you gave me just the information that I needed and could not find anywhere.
I did not stumble across the .basicAuth(USER_SERVICE_EMAIL, USER_TOKEN) parameter to the request in cloud.
I thought that from scriptrunner, these parameters where set to current user or the scriptrunner application user and where not settable in the script.
I tested it and it gave me just what I need.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.