SDM 14.1 and 17.1
PowerShell v4
I have experience in SOAP but not so much REST.
I am trying to get an access_key but there is no result and no errors.
Looking over the online product documents; the SDK samples, and community posts, e.g.. REST webservices , Obtain Access Key didn't help me.
# Force TLS 1.2
###############
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
# Build request
###############
$RESTAPIServer = "<server>"
$RESTAPIUser = "<user>"
$RESTAPIPassword = "<password>"
$BaseAuthURL = "http://" + $RESTAPIServer + ":8050/caisd-rest/rest_access"
$BaseURL = "http://" + $RESTAPIServer + ":8050/caisd-rest"
$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($RESTAPIUser+":"+$RESTAPIPassword))}
$Body = "<rest_access/>"
$ContentType = "application/xml;charset=UTF-8"
# Make the request
##################
Try
{
$SDMSessionResponse = Invoke-RestMethod -Uri $BaseAuthURL -Headers $Header -Method POST -ContentType $ContentType -Body $Body -Verbose -PassThru -OutFile "C:\access_key.txt"
}
Catch
{
Get-Date -Format g
$_.Exception.ToString()
$error[0] | Format-List -Force
}
# Displaying the response
$SDMSessionResponse
## Extracting the access key from the response
$SDMSessionHeader = @{'SDM-api-session-id' = $SDMSessionResponse.value}
$SDMSessionHeader
I have verbose enabled and am sending to a file as well as screen.
Results:
The VERBOSE message isn't helpful. The first line is expected for a POST action and the second says 293 bytes were return but it's not - it's too many for what is shown in $SDMSessionResponse
$SDMSessionHeader shows no value. The access_key.txt file is likewise 0 bytes.
I get access_keys using both SoapUI and Postman but I don't see any difference in the raw code and my construct.
Postman:
POST /caisd-rest/rest_access HTTP/1.1
Host: <server>:8050
Content-Type: application/xml
Authorization: Basic <Base 64 content>
cache-control: no-cache
Postman-Token: bc76dce9-ba73-44e1-b71b-93ae48963fc5
<rest_access/>------WebKitFormBoundary7MA4YWxkTrZu0gW--
SoapUI:
POST http://<server>:8050/caisd-rest/rest_access HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/xml
Content-Length: 15
Host: <server>:8050
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Authorization: Basic <Base 64 content>
I have tried adding the Content-Length in the header - although it appears to be optional - with the same results.
Hopefully, I just need a fresh pair of eyes on this to point out something obvious.
TIA,
J.W.