Use Headers in a vCO REST Operation

vCenter Orchestrator has a built -in plugin for working with systems that support REST API queries. I’ve used this fairly extensively recently while working with vCNS

Out of the box the plugin will do the majority of the hard work for you, however one thing that isn’t available via the Add a REST operation dialogue is the ability to configure a custom header for the REST query. In the following example I need to add an if-match header to update the App firewall rules for a portgroup, but for a POST method I only have the option to specify the Content type:

Per the vCNS API document I need to be able to send  something like the following

POST https:///api/2.0/app/firewall/dvportgroup-28/config –header ‘Content-Type:text/xml’ --header ‘if-match:“1347501121780”’

So we need to dig a bit deeper. After creating a workflow from the REST Operation we have something like the following:

and in the Scripting task, the following code:

Luckily, (and something I hadn’t noticed before) an example for how to set a header has been added as a standard comment:

[code language=“javascript”]

//Customize the request here //request.setHeader(“headerName”, “headerValue”);

[/code]

So in this example we need to add the following:

[code language=“javascript”]

request.setHeader(“If-Match”, generationNumber);

[/code]

First of all though, we will need to add an input for the generationNumber (you can obtain the generationNumber by first of all querying the current ruleset and looking for the Etag header):

Now we can update the Scripting task:

and we can successfully add extra App Firewall Rules when using this workflow now: