Skip to content

Script Controller

Overview

The Script Controller manages script resources and provides compilation endpoints to validate Groovy/Java script syntax before saving. It inherits all standard CRUD, content, and import/export operations from the Resource Controller.

Base path: /api/scripts

Authentication

All endpoints require the X-API-KEY header for authentication.

Inherited Endpoints

All endpoints documented in Resource Controller are available at /api/scripts.

Script-Specific Endpoints

Compile Script by ID

POST /api/scripts/{id}/compile

Compiles the saved content of a script resource and returns the compilation result (success or errors).

Parameters

Name Type In Required Description
id integer (long) query Yes Script resource ID
X-API-KEY string header Yes API authentication key

Note

The id is passed as a query parameter, not a path variable, even though it appears in the path pattern /{id}/compile. This matches the @RequestParam binding in the controller.

Response

Status Description
200 OK Compilation result

CompilationResult schema:

{
  "success": true,
  "errors": []
}

Compilation failure example:

{
  "success": false,
  "errors": [
    "Script1.groovy: 5: unexpected token: } @ line 5, column 1."
  ]
}

Code Examples

package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    apiKey  := "your-api-key"
    baseURL := "https://your-comfly-instance.com"

    req, _ := http.NewRequest("POST",
        baseURL+"/api/scripts/7/compile?id=7", nil)
    req.Header.Set("X-API-KEY", apiKey)

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.*;

public class CompileScript {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(
                    "https://your-comfly-instance.com/api/scripts/7/compile?id=7"))
                .header("X-API-KEY", "your-api-key")
                .POST(HttpRequest.BodyPublishers.noBody())
                .build();
        HttpResponse<String> response = client.send(request,
                HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
import requests

response = requests.post(
    "https://your-comfly-instance.com/api/scripts/7/compile",
    params={"id": 7},
    headers={"X-API-KEY": "your-api-key"}
)
response.raise_for_status()
result = response.json()
if result.get("success"):
    print("Compilation successful")
else:
    print("Errors:", result.get("errors"))
<?php
$ch = curl_init('https://your-comfly-instance.com/api/scripts/7/compile?id=7');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => '',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => ['X-API-KEY: your-api-key'],
]);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
echo $result['success'] ? "Compilation successful\n" : "Errors: " . implode(', ', $result['errors']) . "\n";
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program {
    static async Task Main() {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("X-API-KEY", "your-api-key");
        var response = await client.PostAsync(
            "https://your-comfly-instance.com/api/scripts/7/compile?id=7",
            null);
        var body = await response.Content.ReadAsStringAsync();
        Console.WriteLine(body);
    }
}
require 'net/http'

uri = URI('https://your-comfly-instance.com/api/scripts/7/compile?id=7')
req = Net::HTTP::Post.new(uri)
req['X-API-KEY'] = 'your-api-key'
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
puts res.body

Compile Script by Content

POST /api/scripts/compile

Compiles script source code provided directly in the request body (without saving it first).

Parameters

Name Type In Required Description
X-API-KEY string header Yes API authentication key

Request Body

application/json — A ScriptForm object:

Field Type Required Description
content string Yes The script source code to compile
name string No Script name
type string No Resource type (SCRIPT)

Example:

{
  "name": "MyScript",
  "type": "SCRIPT",
  "content": "def greet(name) { return \"Hello, ${name}!\" }"
}

Response

Status Description
200 OK Compilation result

Example success:

{
  "success": true,
  "errors": []
}

Code Examples

package main

import (
    "bytes"
    "fmt"
    "io"
    "net/http"
)

func main() {
    payload := []byte(`{
        "name": "MyScript",
        "type": "SCRIPT",
        "content": "def greet(name) { return \"Hello, ${name}!\" }"
    }`)

    req, _ := http.NewRequest("POST",
        "https://your-comfly-instance.com/api/scripts/compile",
        bytes.NewReader(payload))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("X-API-KEY", "your-api-key")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.*;

public class CompileScriptByContent {
    public static void main(String[] args) throws Exception {
        String json = "{\"name\":\"MyScript\",\"type\":\"SCRIPT\","
                + "\"content\":\"def greet(name) { return \\\"Hello\\\" }\"}";

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(
                    "https://your-comfly-instance.com/api/scripts/compile"))
                .header("Content-Type", "application/json")
                .header("X-API-KEY", "your-api-key")
                .POST(HttpRequest.BodyPublishers.ofString(json))
                .build();

        HttpResponse<String> response = client.send(request,
                HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
import requests

script_form = {
    "name": "MyScript",
    "type": "SCRIPT",
    "content": "def greet(name) { return \"Hello, ${name}!\" }"
}

response = requests.post(
    "https://your-comfly-instance.com/api/scripts/compile",
    json=script_form,
    headers={"X-API-KEY": "your-api-key"}
)
response.raise_for_status()
result = response.json()
print("Success" if result.get("success") else f"Errors: {result.get('errors')}")
<?php
$data = json_encode([
    'name'    => 'MyScript',
    'type'    => 'SCRIPT',
    'content' => 'def greet(name) { return "Hello, ${name}!" }',
]);
$ch = curl_init('https://your-comfly-instance.com/api/scripts/compile');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => $data,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => [
        'Content-Type: application/json',
        'X-API-KEY: your-api-key',
    ],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $result['success'] ? "Success\n" : "Errors\n";
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program {
    static async Task Main() {
        var form = new { name = "MyScript", type = "SCRIPT",
                         content = "def greet(name) { return \"Hello\" }" };
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("X-API-KEY", "your-api-key");
        var response = await client.PostAsync(
            "https://your-comfly-instance.com/api/scripts/compile",
            new StringContent(JsonSerializer.Serialize(form),
                Encoding.UTF8, "application/json"));
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }
}
require 'net/http'
require 'json'

payload = JSON.generate(
  name:    'MyScript',
  type:    'SCRIPT',
  content: 'def greet(name) { return "Hello, ${name}!" }'
)
uri = URI('https://your-comfly-instance.com/api/scripts/compile')
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json',
                               'X-API-KEY'    => 'your-api-key')
req.body = payload
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) }
puts res.body