NetBackup API call format works in Unix but not Windows
I am running NetBackup 8.2 on a Solaris master. I am writing a script to run on my existing Windows clients for when the server needs to be reinstalled and it needs to have a re-issue token to allow automated installation of the NetBackup software. I have a working version of the script for Linux but I am having an issue converting it to run as a PowerShell script. I have been able to convert all the other API calls but not the POST /security/securitytokens to create the new token. If I use the autogenerate API GUI when connecting to https://MASTER/api-docs/index.html in the security section it will only produce a Unix curl version. I even created a test Windows master server and it also only generates a Unix curl formatted output. I have checked the github site but I could not find a PowerShell example of this API command
The generated code obtained is as follows:
curl -X POST "https://MASTER/netbackup/security/securitytokens" -H "accept: application/vnd.netbackup+json;version=3.0" -H "Authorization: ABCDEFGHIJKLMNOPQRSTUVWXYZ" -H "Content-Type: application/vnd.netbackup+json;version=3.0" -d "{ \"tokenName\": \"test1\", \"hostId\": \"testid\", \"reason\": \"Re-Issue\", \"allowedCount\": 1, \"validFor\": 3600, \"type\": 1}"
I had to change curl to curl.exe to use the true curl program not the alias to Invoke-WebRequest (which format is completely different) and add the -k option. This will produce the following error:
{"errorCode":9926,"errorMessage":"Input JSON is invalid","attributeErrors":{},"fileUploadErrors":[],"errorDetails":[]}
I have tried replacing the \" with ^" and also ' instead of \" but still get the JSON invalid message.
Is there an option or any way to generate the output for Windows PowerShell?
Any help will be greatly appreciated.
Thank you.
So I was finally able to resolve this issue by using the builtin Invoke-WebRequest command. Here is the syntax that I used (Note - auth_header, tokenName and hostId were defined earlier in the script):
$basepath="https://" + $NBU_master + "/netbackup/"
$uri = $basepath + "security/securitytokens"
$reason = "Re-Install"
$allowedCount = 1
$validFor = 3600
$reissue_token = 1
$type = @{
tokenName=$tokenName
hostId=$hostId
reason=$reason
allowedCount=$allowedCount
validFor=$validFor
type=$reissue_token
}
$response = Invoke-WebRequest `
-Headers $auth_header `
-Method POST `
-Uri $uri `
-Body (ConvertTo-Json -InputObject $type) `
-ContentType $content_header_3
$convert = (ConvertFrom-Json -InputObject $response)
$tokenValue=$convert.tokenValue
Thank you for your help.