CA Service Management

 View Only
  • 1.  SDM:  PowerShell REST API - Access Key - no results and no errors

    Posted Dec 05, 2018 10:50 AM

    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:

    PowerShell 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.



  • 2.  Re: SDM:  PowerShell REST API - Access Key - no results and no errors

    Broadcom Employee
    Posted Dec 05, 2018 11:03 AM

    J.W.,

     

    Can you check if :  rest_webservice_resources_to_expose   is deinstalled?  If not, make sure you add appropriate objects that you do want to expose here.

     

    Do look into this option too:  This should be normally set to No + Installed: rest_webservice_disable_basic_auth   

     

     

    _R



  • 3.  Re: SDM:  PowerShell REST API - Access Key - no results and no errors
    Best Answer

    Posted Dec 05, 2018 01:19 PM

    I think you've actually got it but are not looking in the correct object. Check the rest_access attribute of the $SDMSessionResponse object. The access key should be accessible via $SDMSessionResponse.rest_access.access_key.



  • 4.  Re: SDM:  PowerShell REST API - Access Key - no results and no errors

    Broadcom Employee
    Posted Dec 05, 2018 07:56 PM

    Sorry, I misunderstood your post JW, did not realize you said you got keys via SOAPUI+Postman  but only did not get them via powershell.  Grant's suggestion should help here

     

    _R



  • 5.  Re: SDM:  PowerShell REST API - Access Key - no results and no errors

    Posted Dec 05, 2018 10:52 PM

    Yes, that was it.

     

    RTFM

     

    Thanks!

     

    J.W.