Learn Code Stream

Learn Code Stream

VMware vRealize Automation

REST

The REST task is a powerful and adaptable task that lets us interact with any standard REST API - this means we can integrate almost any 3rd party system that has a REST API.

Headers are common accross all the REST action types and allow you to set the HTTP headers to be sent with the API request - often, but not always, these include Content-Type, Accept and Authorization headers - you’ll need to a consult your API documentation to see which headers are required.

If your API requires specific configuration, you can often save time by creating repeatable API tasks as Pipelines, and nest them within your parent Pipeline using the Pipeline Task

REST Action types

The GET action is a simple GET request, which only needs the URL and any Headers to be configured.

Example REST GET request
Example REST GET request

The POST request needs the URL and Headers, as well as a Payload - the format of which is determined by the API you’re interacting with. In the example below I’m using an output parameter from a previous task to populate the Payload.

Example REST POST request
Example REST POST request
Because Code Stream task outputs are already in JSON format it’s normally much simpler to use JSON payloads, like you see in this screenshot. The exported profileJson output parameter is a JSON object that I can use directly in the Payload. If your API gives you a choice of Content-Types, I’d use JSON over XML or YAML.

The PATCH action is most often used to modify an existing object within a REST API - in the example below I’m updating an image profile object. The object ID is supplied as part of the URL (${input.Packer-Build-vRA-Url}/iaas/api/image-profiles/${Release.Create Image Profile JSON.output.exports.imageProfileId}) and the Payload is the updated object specification.

Example REST PATCH request
Example REST PATCH request

The DELETE action will delete an object, typically based on an identifier in the URL. In this example, the deploymentId is supplied from the output of a previous task - ${input.Packer-Build-vRA-Url}/iaas/api/deployments/${Test.Request Deployment.output.responseJson.deploymentId}

Example REST DELETE request
Example REST DELETE request
The REST API task will execute more quickly than a CI task or Custom Integration task because it’s executed directly within the vRealize Automation appliance (or the vRealize Automation Cloud Proxy Agent) rather than on a Docker Endpoint . So, although you can often achieve the same outcome with any of these, the REST task might be preferrable.

Output Parameters

  • status - task status
  • responseHeaders - JSON object representing the HTTP headers
  • responseBody - String property for the API response
  • responseJson - JSON object representing the responseBody
  • responseCode - HTTP response code
Last updated on 26 Apr 2022
 Edit on GitHub