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?
Hello,
Kindly produce your code
My "working example" is the one given on the page you linked to. So we need to see what you're doing differently!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.