Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to call the Confluence REST API from a Scriptrunner script?

Thomas Berger November 3, 2017 edited

I'm trying to call a Confluence REST API endpoint from a Scriptrunner script in Confluence.

I saw this example: https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html#_walkthrough_external_rest_service

But I always get a 'Bad Request' error with the Confluence API.

Anybody got a working example?

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 3, 2017

Hello, 

Kindly produce your code

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 4, 2017

My "working example" is the one given on the page you linked to.  So we need to see what you're doing differently!

Thomas Berger November 4, 2017 edited

Hi Nic,

Can you please comment on placing the same REST call in the 'Script Console' resulting in a 'Bad Request' vs. a 'Custom Endpoint' and everything is working fine.

def httpBuilder = new HTTPBuilder(clientURL)    
def response = httpBuilder.request(Method.GET, ContentType.JSON) { 
uri.path = "/rest/api/content/search"
uri.query = [cql:"$query", os_authType:"basic", os_username:"$username", os_password:"$password"]

 

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 5, 2017 edited

@Thomas Berger

You receive bad request error because your uri.query part is wrong. You use parameters which do not exist in/rest/api/content/search  . You need to  delete all parameters except cql from your uri.query part. 

You have to pass authentication parameters in the header of your request. For example:

httpRequest.addHeader('Authorization', 'Basic ' + 'admin:admin'.bytes.encodeBase64().toString()

Thomas Berger November 6, 2017

Thanks Alexey, the authentication doesn't seem to be the issues here. See also https://developer.atlassian.com/docs/atlassian-platform-common-components/rest-api-development/rest-and-os_authtype as a reference for the method I've used.

The issue is more with the Scriptrunner interface 'Script Console' or my lack of understanding of it.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence whiteboards, whiteboard templates, template contest, visual collaboration, atlassian learning, confluence community, brainstorming tools, agile planning, team productivity, confluence templates, share your template

Share Your Confluence Whiteboard Template for a Chance to Be Featured in the Product! 🏆

Want to leave your mark on Confluence? One winner will have their whiteboard design added into Confluence for all users to access! This is your chance to showcase your creativity, help others, and gain recognition in the Confluence community.

Share your template today!
AUG Leaders

Atlassian Community Events