Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..
517 views

I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

I have an issue while trying to authenticate uCMDB through REST api reference that's provided by uCMDB to generate a token and to use that further to make REST calls so that client can get required CI Information. I could not generate token by doing a POST call.

https://ucmdb-dev.com:8443/ucmdb-browser/rest-api/authenticate

Provided the following key value pairs in the body as per the documentation and also content-type: application/json in the header.

{
"username": "xxxxx",
"password": "xxxxxx",
"clientContext": 1
}

I just could not generate token by making this POST call through postman/Restlet Client. Does it need any certificate to proceed? 

Thanks in advance. 

Here is the response I receive instead of token.
Rest api.PNG

 

Labels (1)
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

Hi, Marko

I found there is one more difference:

Your request URL is : https://x.y.z:8443/ucmdb-browser/rest-api/authenticate

Mine is: https://labucmdb1:8443/rest-api/authenticate

 

View solution in original post

9 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution
i have exactly the same problem. From both Postman and SoapUI, i can't get arround that login response. Using the built-in Swagger server from within CMS UI works fine, but when you want to use the API from outside, it can't pass that login screen, with or without token, even tried using user/pass type of authentication in my POST calls, tried everything i could think of. But then again, i'm a REST API newbie...
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

I did not seem to have this issue.

Here is my request in curl format:

curl -X POST \
https://labucmdb1:8443/rest-api/authenticate \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Authorization: Basic blablabla=' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 78' \
-H 'Content-Type: application/json' \
-H 'Cookie: JSESSIONID=node01x8wp8cqa2qcl1x0ohho5xp2tl0' \
-H 'Host: labucmdb1:8443' \
-H 'Postman-Token: 07832089-f8f6-413d-9f3b-ff81c13bd522,636d7b16-5b5a-4c5f-8d66-568bb959177a' \
-H 'User-Agent: PostmanRuntime/7.17.1' \
-H 'cache-control: no-cache' \
-d '{
"username": "admin",
"password": "blablabla",
"clientContext": 1
}'

 

compare with yours and see what is different.

0 Likes
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution
Hi,
But why should I provide the headers you mentioned like Cookie: JSESSIONID, Postman-Token..so..on?
0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

Hi Bingluo,

okay, but are you getting a Token as a response or that "Login" response?

my postman attempt looks like this:

curl -X POST \
https://XXXXXXX.YYY.ZZZ:8443/ucmdb-browser/rest-api/authenticate \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 79' \
-H 'Content-Type: text/plain' \
-H 'Cookie: JSESSIONID=1683E8BEEC2BF9CA95083E9BDEAA274A; INTERNAL_ACCESS_COOKIE=cLRzaSMYoNg%3D' \
-H 'Host: XXXXXXX.YYY.ZZZ:8443' \
-H 'Postman-Token: d7a3fbdf-62e5-42a3-a653-df5ea97b0021,592c9653-d64b-4fbb-985a-c5bcbb5a761e' \
-H 'User-Agent: PostmanRuntime/7.18.0' \
-H 'cache-control: no-cache' \
-d '{
"username": "admin",
"password": "1111111111",
"clientContext": 1
}'

(I have faked my Hostname and Password for this post)

Instead of expected response (the token), as i'm getting when testing with Swagger on Browser server:

swagger response.JPG

 

...in postman, i'm getting the "login" page, status is still 200, but i'm not getting a token:

postman response text.JPGpostman response preview.JPG

 

So it looks like the API call is successful but can't get past the login screen (which should not be there of course)... So the response is not what we expect (the Token). Any other API call produces the same "successful" response with identical "login" content...

I see the difference in your code: you have the "Authentication: Basic ....".

Can you explain how you set this up (is that the Authentic: Basic type in the Request definition? and what username and password did you supply? The same one used later in the Request body?)

Marko

 

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

even with Authorization set to Basic, i still get the same response, and still no token

postman request.JPG

 

P.S. i'm testing this on UCMDB 2019.02 Windows

 

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

OK, i also had a Content type of text. OK, setting the Authorization (Basic, with my admin username and password provided) and with application/json content, still no change.

Here is my request:

 

curl -X POST \
https://x.y.z:8443/ucmdb-browser/rest-api/authenticate \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Authorization: Basic ***************' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 79' \
-H 'Content-Type: application/json' \
-H 'Cookie: JSESSIONID=70013EBEF327C2A220ED0E097B96A430; INTERNAL_ACCESS_COOKIE=cLRzaSMYoNg%3D' \
-H 'Host: x.y.z:8443' \
-H 'Postman-Token: 42192870-30e4-43ec-9b95-dfdf0c37fa51,1dbdcb15-0a00-4863-845f-67df05daaeb9' \
-H 'User-Agent: PostmanRuntime/7.18.0' \
-H 'cache-control: no-cache' \
-d '{
"username": "admin",
"password": "*******",
"clientContext": 1
}'

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

Hi, Marko

I found there is one more difference:

Your request URL is : https://x.y.z:8443/ucmdb-browser/rest-api/authenticate

Mine is: https://labucmdb1:8443/rest-api/authenticate

 

View solution in original post

Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

Hi Bingluo @bingluo 

You nailed it! I was targeting the wrong server all along!

But it's not my fault! I wanted to explore the REST API possibilities, so of course i started with online MF documentation. So i go to the Develop->API Reference (https://docs.microfocus.com/itom/Universal_CMDB:2019.02/API_Ref)

From there it takes me to CMS REST API Reference (https://docs.microfocus.com/UCMDB/2019.02/ucmdb-docs/docs/eng/APIs/UCMDB_RestAPI/index.html).

There is a line saying:

"Note: To view the interactive REST API Reference documentation and to try executing the sample code for each REST API call, access CMS UI, and go to Help > REST API Reference."

Not once there is no mention that the target for REST calls should be the UCMDB server!

So i followed that NOTE and ended up experimenting the REST API calls on UCMDB BROWSER server!

Never, on any line in the docs i haven't seen that i should actually point my requests to UCMDB server!!!

Thank you so much for spotting this, i have altered my Postman calls and now they work fine!

So the solution to my problem is to send REST API calls to:

https://ucmdb_server:8443/rest-api/

Thanks, regards

@Kartiki believe this will solve your issue as well

 

 

0 Likes
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Re: I have an issue while invoking rest api authenticate to generate token from rest client.

Jump to solution

Indeed, thank you @bingluo !

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.