How to write groovy code to access URLs with authentication (account password)?
443666 verification code
已解决
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 URLSdef csdURL ='http://status.ops.com/'def csdincident = 'api/incidents'def csdevent = '/api/events'def date = new Date()def sdf = new SimpleDateFormat("yyyy-MM-dd")//DEFINE SERVICE IDSdef EOD = 'b56aec29-cb7b-42ec-a329-aeab124b6e84'//CREATE ACCESS BEARER TOKENdef 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'
It looks like you're new here. Sign in or register to get started.