Monday, 10 July 2017

WFA 4.1 RESTful API: A Few Notes + Some PowerShell

OnCommand Workflow Automation (WFA) 4.1 REST APIs are very well documented here: REST Web Services Primer.

WFA Object Collections

Putting the following URLs in a browser returns (mostly) XML output for the specific WFA object collections:

https://{host:port}/rest/backups (this returns a backup)
https://{host:port}/rest/dars (this returns a DAR)
https://{host:port}/rest/configurations (could not find resource...)
https://{host:port}/rest/search (needs a search term)

Note: The list above is similar to what’s under ‘WFA object collection’ on page 8 of the REST Web Services Primer.

A Bit of PowerShell

If you’re still using a self-signed certificate on your WFA box, you’ll probably want to do>

$TypeToAdd = "using System.Net;using System.Security.Cryptography.X509Certificates;public class TrustAllCertsPolicy : ICertificatePolicy {public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) {return true;}}"

add-Type $TypeToAdd

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

Otherwise you’ll get an error - when you try to run Invoke-RestMethod - like “The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel”.

To configure credentials this one liner will do the job>

$C = New-Object System.Management.Automation.PsCredential($(Read-Host "U"),$(Read-Host "P" -AsSecureString))

With PowerShell you can use either Invoke-RestMethod or Invoke-WebRequest. Invoke-RestMethod is more convenient since it only returns the content, omitting the headers.

A Few GETs

WFAs REST API supports the verbs: GET (list), POST (add), PUT (update), DELETE (remove)

Here are a few examples of GET-ing information via the REST API (hope to do some POST/PUT/DELETEs in a future post).

Example 1: Getting All the Users

$Users = Invoke-RestMethod -Method Get -uri https://{host:port}/rest/users -Credential $C
$Users.collection.user | FT name,roleType -AutoSize

Image: A Simple WFA REST API Get Example
Example 2: Get a List of All the Workflows
Note: This might take a few seconds to run...

$Workflows = Invoke-RestMethod -Method Get -uri https://{host:port}/rest/workflows -Credential $
$Workflows.collection.workflow | FT name,uuid -AutoSize

Example 3: Getting a Specific Workflow

$Workflows = Invoke-RestMethod -Method Get -uri https://{host:port}/rest/workflows?name="Migrate Volumes" -Credential $C

No comments:

Post a Comment