I’m trying to get jwt token in helix/bmc remedy using script console but it always outputs to null without logs. I’ve hidden the confidential informations
Could you please share your code in a text format, so I can review it and provide some feedback?
Also, if you are trying to connect to an external REST Service, I suggest using this Adaptavist Library example.
I am looking forward to your feedback.
Thank you and Kind regards,
Ram
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import groovyx.net.http.ContentType
def http = new HTTPBuilder("https://www-mbl-test:11443")
def data = http.request(Method.POST,ContentType.URLENC){ req ->
uri.path = "/api/jwt/login"
body = [username:"USERNAME", password:"PASSWORD"]
response.success = { resp, jsonData ->
log.error("success"+resp.statusLine);
assert resp.status == 200
return jsonData
}
response.failure = {resp ->
log.error("failure")
return null
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For your requirement, you should instead try using a GET request instead of a POST request.
Below is a sample code for your reference:-
import groovy.json.JsonOutput
import groovyx.net.http.ContentType
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
final externalUrl = "https://www-mbl-test:11443"
def getResponse = get(externalUrl, '/api/jwt/login', '')
if (getResponse) {
def responseGetMap = getResponse as Map
responseGetMap
}
def get(def hostUrl, def endpoint, def query) {
if (hostUrl.toString().contains('&') || hostUrl.toString().contains('?')) {
log.error 'The parameters of the endpoint must be included in the query variable'
return
}
def username = '<YOUR_USERNAME>'
def password = '<YOUR_PASSWORD>'
def client = new RESTClient(hostUrl)
def headers = ['Authorization': "Basic ${"${username}:${password}".bytes.encodeBase64()}", 'Accept': 'application/json'] as Map
client.setHeaders(headers)
client.handler.success = { HttpResponseDecorator response, json ->
log.warn "======>>>> ${response.statusLine}"
log.warn "======>>>> ${json}"
json
}
client.handler.failure = { HttpResponseDecorator response ->
log.error response.entity.content.text
[:]
}
client.get(path: endpoint, queryString: query, contentType: ContentType.JSON )
}
Please note that the sample code above is not 100% exact to your environment. Hence you will need to make the required modifications.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.