HPE OneView
cancel
Showing results for 
Search instead for 
Did you mean: 

Set default login directory

 
SOLVED
Go to solution
Highlighted
Respected Contributor

Set default login directory

Trying to set the default login directory using the REST API.  I ran: 

# Follow instructions in: OneView-API_Get_Session_Credentials.txt
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --data "{ \"allowLocalLogin\"" true, \"defaultLoginDomain\"; { \"loginDomain\": \"2\", \"name\": \"${ADD}\", \"type\": \"LoginDomainConfigInfoDto\", \"uri\": \"/rest/logindomains/s\" }}" \
     --request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'

which gives back: 

{
  "data": {},
  "nestedErrors": [],
  "errorSource": null,
  "recommendedActions": [
    "Correct the JSON as appropriate array or collection and try the request again."
  ],
  "details": "The JSON sent in the request is not a valid array or collection.",
  "message": "The JSON can not be mapped to array or collection.",
  "errorCode": "INVALID_JSON_ELEMENT"
}

If I just echo the data segment to jq, I get: 

echo "{ \"allowLocalLogin\"" true, \"defaultLoginDomain\"; { \"loginDomain\": \"2\", \"name\": \"${ADD}\", \"type\": \"LoginDomainConfigInfoDto\", \"uri\": \"/rest/logindomains/s\" }}" | jq -r '.'
{
  "defaultLoginDomain": {
    "uri": "/rest/logindomains/2",
    "type": "LoginDomainConfigInfoDto",
    "name": "HQ",
    "loginDomain": "2"
  },
  "allowLocalLgin": true
}

which looks fine as far as I can tell.  Anyone have an idea what I am doing wrong?

 

18 REPLIES 18
Highlighted
HPE Pro

Re: Set default login directory

You are using the wrong URI to set the default directory.  The correct URI would be:

 

POST    https://{appl}/rest/logindomains/global-settings/default-login-domain

Auth: abcdefghijklmnopqrstuvwxyz012345
X-Api-Version: 1000
Content-Type: application/json

"myDirectoryName"

This is documented in our REST API reference document, under Login Domains Global Settings.  You could have searched that same API documentation for default directory:

OneView Default Directory API Search.jpg

 


I am an HPE employee

Accept or Kudo

Highlighted
Respected Contributor
Solution

Re: Set default login directory

Sorry Chris, I just realized I never closed this out.  I did get it working with: 

#
# Set the default login directory
# First, get a listing of configured directories:
curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}/rest/logindomains | jq -r '.'
# From the above, get the loginDomain number and the corresponding uri:
LGURI="/rest/logindomains/2"
LGDOMNUM="2"
# Note: If you have only one directory configured, can set LGURI directly with:
LGURI=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}/rest/logindomains | jq -r '.members[] | .directoryServers[] | .uri')
# And the LGDOMNUM with:
LGDOMNUM=$(curl --insecure \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}/rest/logindomains | jq -r '.members[] | .loginDomain')
ADD="ADHQ"
DATA='{ "allowLocalLogin": true, "defaultLoginDomain": { "loginDomain": "'${LGDOMNUM}'", "name": "'${ADD}'", "type": "LoginDomainConfigInfoDto", "uri": "'${LGURI}'"
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --data "${DATA}" \
     --request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'
Highlighted
Occasional Advisor

Re: Set default login directory

Hi Brad,

Looks like you pasted the old request !

Did you have to change the URI to /rest/logindomains/global-settings or the request body to pass only the directory name as string as Chris suggested? Is it possible for you to confirm and update the request so that it can help anyone else facing a similar issue?

DATA='{ "allowLocalLogin": true, "defaultLoginDomain": { "loginDomain": "'${LGDOMNUM}'", "name": "'${ADD}'", "type": "LoginDomainConfigInfoDto", "uri": "'${LGURI}'"
curl --insecure \
--header "content-type: application/json" \
--header "X-API-Version: ${currentVersion}" \
--header "auth: ${sessionID}" \
--data "${DATA}" \
--request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'

~Poongkodi

Highlighted
Respected Contributor

Re: Set default login directory

You are right that I don't have that correct.  However, the documentation needs some work.  For example, the REST API reference, the "Authorization" section states: "This API requires no authorization."  However, the "Request" section shows an "Auth" line and the "Request Headers" section has an Auth entry with: "Session authorization token obtained from logging in.  If this header is not included or if the session-token is invalid, the response code will be 401 Unauthorized."  It definately could use a better example of what is required in the request body.  I tried: 

 

DATA="ADHQ"
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --data "${DATA}" \
     --request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'

 

and get back malformed JSON.  I tried: 

 

DATA='{ "name": "ADHQ" }'

 

 and get back invalid JSON.  The REST API reference "Request Body" section talks about a very large number of items.  I ran: 

 

curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --request GET ${OneView}/rest/logindomains/global-settings | jq -r '.'

 

and copied the entire section related to ADHQ into the DATA variable and tried again.  I got back that the JSON sent in the request is not a valid array or collection.  Like I said, the API reference is not clear.  Could someone please provide a more clear example of what is the proper JSON to supply for setting the default login domain?

Highlighted
Respected Contributor

Re: Set default login directory

Well, from a previous conversation, Set default login domain back to local, implies just the directory name.  So, I tried:

 

ADD="ADHQ"
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --data "${ADD}" \
     --request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'

 

but that still gives me "malformed JSON cannot be parsed."

Highlighted
Occasional Advisor

Re: Set default login directory

Hi Brad,

I see that you missed to surround the value with quotes like you mentioned in the other thread.

Try

ADD="ADHQ"
curl --insecure \
--header "content-type: application/json" \
--header "X-API-Version: ${currentVersion}" \
--header "auth: ${sessionID}" \
--data '"${ADD}"' \
--request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'

Thanks.

Highlighted
Respected Contributor

Re: Set default login directory

No, that was not it.  I found in the REST API reference, that "MALFORMED_JSON" means that the data did not parse as JSON.  Just having the name "ADHQ" is not a JSON.  So, I attempted: 

DATA='"name": "'${ADD}'"'
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --data "${DATA}" \
     --request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'

and this time got back:

Invalid global settings.  Property: name, Value: {1}\nThe specified enterprise directory name name does not exist.

AUTHN_GLOBALSETTINGS_VALIDATION_RESOURCE_ERROR

Not sure what that means?  When I retrieve a listing of the logindomains, that field, name, has value ADHQ.  So, what am I missing?

Highlighted
Trusted Contributor

Re: Set default login directory

hi @BradV 

Sorry about the trouble this API has been causing you.
There is something odd about this specific API.
We have taken your input.
This specific API does not accept standard JSON as the POST body.
So in your attempt below, you have DATA: { "name" : "AHQ" } which is what you would expect a standard API to accept.
While most of our other APIs do accept a format such as this, this specific one instead takes just a string "ADHQ" enclosed in double quotes as the *only* input in the POST body.

So do not pass the DATA = '"name": "'${ADD}'"' as the argument to --data.
Instead you need to pass just --data "ADHQ" as the argument.

When doing this from curl on the command line, the below would work.

curl --insecure \
--header "content-type: application/json" \
--header "X-API-Version: ${currentVersion}" \
--header "auth: ${sessionID}" \
--data '"ADHQ"' \   #(that is an opening single quote followed by ADHQ in double quotes followed by a closing single quote)
--request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'

Try after making that change. I have justed tested it and that works. 

DATA='"name": "'${ADD}'"'
curl --insecure \
     --header "content-type: application/json" \
     --header "X-API-Version: ${currentVersion}" \
     --header "auth: ${sessionID}" \
     --data "${DATA}" \
     --request POST ${OneView}/rest/logindomains/global-settings/default-login-domain | jq -r '.'

And let us know.
Thank you for being patient with this. 

Regards,
Bhaskar


I am an HPE employee

Accept or Kudo

Highlighted
Respected Contributor

Re: Set default login directory

Hi Bashkar,

When I just give the name, it responds with malformed json.  When I remove the '--header "content-type: application/json",' the error message changes to: "Invalid global settings.  Property: ADHQ=, Value: {1}\nThe specificed enterprise directory name ADHQ= does not exist."

So, this API is not correctly documented.  This API reference also states no authorization is required.