Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to write groovy code to access URLs with authentication (account password)?

white November 1, 2022

How to write groovy code to access URLs with authentication (account password)?

3 answers

0 votes
Kevin Dalton
Contributor
November 2, 2022

Have you tried using Postman to get the Bearer token and using it in your logic?  Here is an except with token edited and URL edited

//DEFINE CSD URLS
def csdincident = 'api/incidents'
def csdevent = '/api/events'
def date = new Date()
def sdf = new SimpleDateFormat("yyyy-MM-dd")
//DEFINE SERVICE IDS
def EOD  = 'b56aec29-cb7b-42ec-a329-aeab124b6e84'
//CREATE ACCESS BEARER TOKEN
def access_token = '
def access_token1 = 'eyJ0LJDMmnasdlkjN'
'
   
def http = new HTTPBuilder(csdURL)
//EOD Incident
   def svcSearch = '?service_id=' + EOD + '&unresolved=true'
   def GETsearch = (     http.request(GET, JSON) { req ->
            uri.path = csdincident+svcSearch
            headers.'Authorization' = "Bearer  $access_token"
            headers.'Content-Type' = 'application/json'
            headers.'User-Agent' = 'Mozilla/5.0'
0 votes
white November 1, 2022

已解决

0 votes
Ananta baral
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 1, 2022

443666 verification  code

Suggest an answer

Log in or Sign up to answer