Ask The Experts

SnapCenter API Error 500

MrFilipot
5,667 Views

Hello,

 

I'm testing SnapCenter API and for example this CURL...

 

curl -X GET --header 'Accept: application/json' --header 'Token: ThisIsMyValidToken' 'https://10.240.141.20:8146/api/4.1.1/hosts/mytesthost.dns.suffix/resources'

 

...only ends up in getting following JSON response:

 

{
"Message": "An error has occurred."
}

 

It behaves like this for all my registered hosts (with discovered and protected resources). All my test hosts are WIN VMs with iSCSI disks.

Documentation says I should download logs and search through them. I did. I found nothing.

 

Does anyone have a suggestion what to do next?

Thanks!

 

2 REPLIES 2

Brolley_Mike
5,320 Views

I do not have extensive experience with this, but it seems no one else is answering.  So, I will provide my barely understood example in hopes that it helps you.

 

The token works only so long, and it looks a bit like this (one of mine that is no doubt long expired):

 

"KlYxOg==OWFjNGIxZGMtZjg3Ni00MTc1LWE2NmUtMGZiM2ZjZDkwMzJk8xxGKBQ4wVrDjAD39GTyWPYctSN+ggjv2cpsjU+JMelnbeK2kldNrbHCvghQ6GW5zFuN7DrjJH5D1heWZiJQ/uyd+8tNO8mnh/K1a5Sr8/gktvycnzkP5PukRDHbt6lLiTR6BTvXccxYMjzNbgwXyJEn6FIowsd5prTpSTLguVeX3WLcwdd9Q8fhM10pjDSPA8N1Pgqm/yT4q+4XpPL9hQ=="

 

This will go into your JSON file, somewhere.  I assume this is so, and something else has gone wrong.

 

Now, for the example:

 

==============================================================================
# Login into the SC server. If successful, save the token as a ENV variable
if [ $# -lt 3 ]
then
echo Usage $0 Domain User ServerName/IP Role
echo Default role: SnapCenterAdmin
echo Password will be asked for when the command is run
exit 99
fi
if [ -z $4 ]
then
ROLE="SnapCenterAdmin"
else
ROLE=$4
fi
DN=$1
UNAME=$2
SN=$3

echo Password:
read -s PASS

TOKENFILE=~/.SC_Token.json
curl -X POST --insecure --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"UserOperationContext": {"User": {"Name": "'${DN}'\\'${UNAME}'","Passphrase": "'${PASS}'","Rolename": "'${ROLE}'"}}}' 'https://'${SN}':8146/api/4.1/auth/login\?TokenNeverExpires=false' > $TOKENFILE 2>/dev/null

if [ `cat $TOKENFILE |jq .Result._errorCode` -ne 0 ]
then
echo `cat $TOKENFILE |jq .Result._message`
exit 1
else
echo Login successful. Token received.
fi
=========================================================================================================

 

Once this is in-place, the following script reads information from the SnapCenter server.

 

=========================================================================
# View the host information
if [ $# -lt 1 ]
then
echo "Usage $0 [--PluginInfo=<true|false>] --server=<ip or hostname of SC server> --OSType=<Linux|Windows|VSphere>"
exit 99
fi
for i in "$@"
do
case $i in
--PluginInfo=*)
PINFO="${i#*=}"
shift # past argument=value
;;
--server=*)
SN="${i#*=}"
shift # past argument=value
;;
--OSType=*)
OSTYPE="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
if [ `echo $PINFO|wc -c` -lt 3 ]
then
PINFO=true
fi
TOKENFILE=~/.SC_Token.json
if [ ! -e $TOKENFILE ]
then
echo "You must run 'login' and get a token before you can use this command."
exit -1
fi

FILE=~/.SC_Host.json
TOKEN=`jq .User.Token $TOKENFILE`
TOKEN=`echo "${TOKEN:1:${#TOKEN}-2}"`

curl -X GET --insecure --header 'Accept: application/json' --header 'Token: '$TOKEN'' 'https://'$SN':8146/api/4.1/hosts?IncludePluginInfo='$PINFO'&IncludeVerificationServerInfo=false&OperatingSystemName='$OSTYPE'' > $FILE 2>/dev/null
if [ `cat $FILE |jq .Result._errorCode` -ne 0 ]
then
echo `cat $FILE |jq .Result._message`
exit 1
else
jq . $FILE
fi
===================================================================================

 

Note: jq is a JSON parser.  It is available online.

 

Hopefully, this example/demonstration script pair is helpful to you for adapting your attempt to a working condition.

 

Thanks,

Mike Brolley

 

 

 

MrFilipot
5,269 Views

Hello Mike, it's not the token - I cut short the curl from my original post to make it more readable. In reality I'm using correct and working token (it works for other API calls). I will check your script but other API calls work and only the calls directed to /resources/ don't. I will check your script though, maybe I'll find something.

Public