def API_KEY = "your API key"
def FILESYSTEM_IDS = ["F_ID1", "F_ID2"]
def PIPELINE_ID = "your pipeline ID"

// Build the JSON manually
def jsonPayload = '{"filesystemIds":["' + FILESYSTEM_IDS.join('","') + '"],"pipelineId":"' + PIPELINE_ID + '"}'

// Endpoint URL
def URL_STRING = "https://app.biodock.ai/api/external/analysis-jobs"

// Open a connection
def url = new URL(URL_STRING)
def connection = url.openConnection() as HttpURLConnection
connection.setRequestMethod("POST")
connection.setRequestProperty("X-API-KEY", API_KEY)
connection.setRequestProperty("Content-Type", "application/json")
connection.doOutput = true

// Write the JSON payload to the request body
connection.outputStream.withWriter("UTF-8") { writer ->
    writer.write(jsonPayload)
}

// Get the response
def responseCode = connection.responseCode
def responseText

// If the response code is successful, read from input stream, else read from error stream
if (responseCode >= 200 && responseCode < 300) {
    responseText = connection.inputStream.text
} else {
    responseText = connection.errorStream?.text
}

// Print the response
println("Response Code: ${responseCode}")
println("Response Body: ${responseText}")
