REST API execution

Infraxys provides a REST API that can be used to manage any module related resources and to execute actions and workflows.

This API can be called from external systems or from Infraxys actions themselves.

Authentication

Authentication can be done in two ways: using OAuth2 like the Infraxys web application, or using personal access tokens.

For server-to-server requests, personal access tokens is the easiest way.
When using the token, the account of the user that owns the token is used. So it’s important to keep that in mind when assigning and removing teams for the user.

Using a personal access token

  • Login to Infraxys with the (technical) user account for which a token should be created.
  • Open the “Settings”-view.
  • Select the “Personal tokens”-tab.
  • Right-click in the table to add or remove tokens.

NOTE: Tokens are only visible at the time of creation!

Delete a token if it shouldn’t be usable anymore. You can only see tokens of the account that you’re logged in with.

Calling the REST API

The API of Infraxys developer can be called without an authorization-header.
For Infraxys server, a header like ‘Authorization: token xxx’ is required.

Use variables like the following in the requests below.

pat_token="<enter your token here>"
branch="<enter the Git-branch of the instance or workflow you want to execute actions from>"
instance_id="<enter the id of the instance you want to execute an action from>"
environment_id="<enter the id of the environment you want to execute an action from>"
workflow_id="<enter the id of the workflow that you want to execute>"; 
filename="<enter the filename of the packet of the instance. This file must be marked executable>"

The contents of “argument” will be available as read-only JSON file “/tmp/infraxys/system/custom/arguments.json” for the action. Every action of a workflow will can use the file.

Executing actions

Workflows

data=$(cat <<EOF
{
    "asynchronous": false,
    "argument": {
        "namespaceName": "my-namespace",
        "limits": {
            "cpu": 4,
            "memory": "4Gi"
        }
    }
}
EOF
);

url=https://localhost:8444/api/v1/environment/$branch/$environment_id/workflow/$workflow_id/execute

curl -k -X POST --url $url \
    -H "Authorization: token $pat_token" \
    -H 'content-type: application/json' \
    -d "$data"

Instance actions

data=$(cat <<EOF
{
    "asynchronous": false,
    "argument": {
        "ticketNumber": "1245",
        "ticketSystem": "ServiceNowProd",
        "caller": "ourSchedulingSystem"
    }
}
EOF
);

url=https://localhost:8444/api/v1/instance/$branch/$instance_id/files/$filename/execute

curl -k -X POST --url $url \
    -H "Authorization: token $pat_token" \
    -H 'content-type: application/json' \
    -d "$data"