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

Scriptrunner cURL error, ignore -H option Edited

It appears that my script is missing my -H option when I am trying to get a response. It is complaining that it is a syntax issue, but it doesn't appear to be. Anyone seen this issue before? I have taken out any identifying info about the API. I have tested this in a terminal, and it returns data correctly

Code:

import org.apache.log4j.Level
import org.apache.log4j.Logger

def log = Logger.getLogger("com.acme.workflows")
log.setLevel(Level.DEBUG)

def headers = "Bearer 12345678-1234-1234-1234-123456789120"
//def response = "curl -H \"Authorization: Bearer 12345678-1234-1234-1234-123456789120\" https://url.com/api/path/end"
def response = 'curl -H \'Authorization: Bearer 12345678-1234-1234-1234-123456789120\' https://url.com/api/path/end'
def proc = response.execute();
proc.waitFor();

log.debug(proc.exitValue())
log.debug(proc.err.text)
log.debug(proc.in.text)

 

I have also tried without the escapes (\') and with double quotes. It seems like each combination is still throwing errors

 

Errors:

curl: (6) Could not resolve host: Bearer; Name or service not known

curl: (6) Could not '; Name or service not known

Response:

{"timestamp":1578586566943,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource","path":"/api_data/all_data"}

1 answer

What are you trying to access from the API?  Is there a reason you can't leverage the com.atlassian.jira libraries?

I was not aware there were libraries that could handle those calls

I am trying to access a remote DB that stores details information regarding to billing. The return should be a json dump of information.

Ah gotcha.  Didnt realize you were calling out to an external endpoint.  In that case a few things to note:

1. The error is saying "could not resolve host" which indicates that it's not catching the parameters as being part of the header arg but instead as the target address.  This indicates that the value isnt being recognized as a header value...the quotes arent getting passed through.

Try:

def response = "curl -H 'Authorization: Bearer 12345678-1234-1234-1234-123456789120' https://url.com/api/path/end"

2. Use HttpClient instead for all it's benefits

3. You may have compromised your access token.  get a new one before you push this to a production environment ;)

curl: (6) Could not resolve host: d4483b04-e671-4042-94fd-db2027f3a5cd'; Name or service not known

Yikes you are right. It has to be regenerated anyways. I will try your suggestions in the morning, but do you have an example of the httpclient?

Suggest an answer

Log in or Sign up to answer
TAGS

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