Login to RTC using oslc and rest

581 Views Asked by At

I am new to Rational team concert. Please if anyone knows, can you help me how to login to rational team concert using oslc and rest API with so sample code

Thanks.

1

There are 1 best solutions below

0
On

In Python

base_url = "https://jazzccm.domain:9443/ccm"
auth_url = '/authenticated/identity'
workItem_url = "https://jazzccm.domain:9443/ccm/oslc/workitems/"
session = requests.Session()
session.verify = False
session.allow_redirects = True
session.headers = {'accept':'application/json'}
session.auth = (username,password)
# authenticated user
response = session.get(base_url + auth_url)
print(str(response.headers))
print(str(response.status_code))
if 'x-com-ibm-team-repository-web-auth-msg' in response.headers and response.headers['x-com-ibm-team-repository-web-auth-msg'] == 'authrequired':
    print("Not authenticated yet")
    login_response = session.post(base_url + '/j_security_check', data={'j_username':username, 'j_password':password})
    print(str(login_response.headers))
    print(str(login_response.status_code))
    if 'x-com-ibm-team-repository-web-auth-msg' in login_response.headers and login_response.headers['x-com-ibm-team-repository-web-auth-msg'] == 'authrequired':
        print(str(login_response.status_code))
        print("Exit HEre")
        sys.exit(1)
    response = session.get(base_url + auth_url)
response = session.get(workItem_url + number + '.json')
print(str(response.json()))
json_data = response.json()

In DXL

// Usuall Taken from some link or some doors link
resourceURL = "https://jazzccm.domain:9443/ccm/oslc/workitems/number.json"
// create the header
HttpHeader reqHeader = null
// no body is necessary
HttpBody reqBody = null
// send request
HttpResponse resp = HttpRequest(HttpGet, resourceURL, reqBody, reqHeader)
if (resp != null)
{
    HttpHeaderEntry entry
    Buffer buff = create
    buff += "*** STATUS ***\n"
    buff += resp.code "\n"
    buff += "*** HEADER ***\n"
    // another example of the header iterator
    for entry in resp.header do
    {
        buff += entry.key
        buff += ":"
        buff += entry.value
        buff += "\n"
    }
    buff += "*** BODY ***\n"
    HttpBody respBody = resp.body
    if (respBody != null)
    {
        buff += stringOf(respBody.value) ""
    }
    else
    {
        buff += "No body was returned."
    }
    // display the response
    displayRich("\\pard " stringOf(buff))
    // remember to delete the buffer
    delete buff
    // remember to delete the response
    delete resp
}