Skip to content

HTTP task type

The Site Controller can execute http(s) requests as part of a workflow or other types of extensions. This is done via the ExtensionTaskWebhook task type.

Creating an extension that executes an http request

Section titled “Creating an extension that executes an http request”
  1. Create a file called http-request-extension.json with the following content:
{
"kind": "ExtensionDefinition",
"schemaVersion": "1.1",
"name": "Server registration webhook",
"label": "server_registration_webhook",
"extensionType": "workflow",
"vendor": "MetalSoft",
"extensionVersion": "1.0.0",
"description": "Notifies an external system when a server is registered",
"icon": "none",
"dependencies": {
"controllerVersion": "v7.4.0"
},
"inputs": [],
"outputs": [],
"assets": [],
"onAssetChange": [
{
"stage": "serverRegistered",
"tasks": [
{
"label": "notify-external-system",
"taskType": "ExtensionTaskWebhook",
"options": {
"endpoint": "https://cmdb.example.com/api/servers",
"method": "POST",
"headers": { "Content-Type": "application/json" },
"requestTemplate": "{\"vendor\": \"{{ server.vendor }}\", \"serial\": \"{{ server.serialNumber }}\"}",
"expectedResponseStatuses": [200, 201],
"timeout": 120
}
}
]
}
]
}
  1. Create the extension, publish it and make it public:
Terminal window
metalcloud-cli extension create test-http workflow "test-http" --definition-source http-request-extension.json
metalcloud-cli extension publish test-http
metalcloud-cli extension make-public test-http
  1. You are now finished. Attempt a server register and watch for workflow-related tasks in the registration graph.
{
"label": "notify-external-system",
"taskType": "ExtensionTaskWebhook",
"options": {
"endpoint": "https://cmdb.example.com/api/servers",
"method": "POST",
"requestTemplate": "{\"vendor\": \"{{ server.vendor }}\"}",
"expectedResponseStatuses": [200, 201],
"timeout": 120
}
}
  • endpoint - The endpoint to call. Must be a valid URL (≤128 chars).
  • method - The method to use, one of GET, POST, PUT, PATCH, DELETE.
  • headers - An object of headers to send such as: "headers": {"Content-Type": "application/json", "header2": "value2"}.
  • requestTemplate - Required. The payload of the request. It can be a Nunjucks (a subset of Jinja2) template referencing the stage payload objects.
  • expectedResponseStatuses - An array of accepted status codes such as [200, 201] (up to 12 entries).
  • timeout - Timeout in seconds (1–30000). Defaults to 30 seconds.
  • insecureSkipVerify - If set to true it will ignore TLS certificate validation failures. Defaults to false.

The objects available to the requestTemplate depend on the stage the task is attached to — for example the server object for serverRegistered, or the serverDNSRecordSet object for serverCreateDNS. See Stage payloads for the full payload of every stage.