Example REST API curl procedure in powershell
search cancel

Example REST API curl procedure in powershell

book

Article ID: 407376

calendar_today

Updated On:

Products

CA Automic Applications Manager (AM)

Issue/Introduction

Below is an example of how to use the new REST API in Applications Manager 9.6.0 and above using curl commands in powershell

Resolution

Please note the following is just an example.  A knowledge of powershell and the REST API are necessary to implement this.  Errors from powershell need to be reviewed by OS admins.

  • Start by encoding the username and password in a string: username:password       For example, with the username admin and password admin, you could run:

    $stringToEncode = "admin:admin"
    $encodeString = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($stringToEncode))

  • Running the following will print that string:

    $encodedString

  • You can then retrieve the Authorization token by consuming the POST method for the /auth endpoint and set it to the $bearer_token variable:

    $bearer_token = curl -X POST "http://[RESTI API servername or IP]:[REST API port]/auth" -H "Authorization: Basic $encodedString" -H "Content-Type: application/json"

  • This can then be used for additional REST API endpoint consumption.  For example, you can use the following to get an agent list:

    curl "http://[RESTI API servername or IP]:[REST API port]/api/agents" -H "Authorization: Bearer $bearer_token"

This will bring back the result with all agents as you would see them in the UI.