Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Facing issues with using external API's in Scriptrunner

Edited

Hi,

I am using the latest versions of ScriptRunner and Jira Software (Server).

I am trying to fetch data from an External System into Jira using REST API's through ScriptRunner.
External API's seem to work fine when used with the 'Postman' tool and CURL command.
But, when used with ScriptRunner, I am getting the following error:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.apache.http.conn.ssl.SSLSocketFactory.createLayeredSocket(SSLSocketFactory.java:570)

The following are the CURL commands that run successfully:
GET Request:


curl -H "Authorization: Bearer sampleToken" https://sample.url.com/employeesapi/api/employees/testuser

POST Request:


curl -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -X POST -d "username=Jira&password=SamplePassword&grant_type=password" https://sample.url.com/securityapi/oauth/token

The following is the script being used with ScriptRunner:
GET Request:

import groovy.json.JsonOutput
import groovyx.net.http.ContentType
import static groovyx.net.http.ContentType.*
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import static groovyx.net.http.Method.*

def client = new RESTClient('https://sample.url.com.com/employeesapi/api/employees/testuser')
def token = "SampleToken"

client.setHeaders([
'Accept' : ContentType.JSON,
'Authorization': "Bearer $token"
])

client.get(
contentType: ContentType.JSON
)

 

POST Request:

import groovy.json.JsonOutput
import groovyx.net.http.ContentType
import static groovyx.net.http.ContentType.*
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import static groovyx.net.http.Method.*

def client = new RESTClient('https://sample.url.com/securityapi/oauth/token')
client.setHeaders([
'Accept' : 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
])

client.post(
path: 'update.json',
body: [ "username": "Jira", "password": "SamplePassword", "grant_type":"password" ],
requestContentType: URLENC
)

 

Any ideas or suggestions on getting rid of the SSL error?

Thanks,

Rupa

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

How we use Jira Service Management for our recruitment process! - Part 2

It is never about setting up a process and being done with it. Rather, the focus should always be on optimizing it for the best outcomes. Thus, we didn’t stop at setting up JSM for our recruitment pr...

216 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you