I'm stuck with my custom script

I’m trying to implement my own groovy script but I’m stuck at some parts and I was wondering if anybody could help me? I’ve documented is as best as I could.

<?xml version="1.0" encoding="UTF-8"?>
<config
	xmlns="http://web-harvest.sourceforge.net/schema/1.0/config"
	scriptlang="groovy">
	<robotics-flow>
		<robot driver="universal" close-on-completion="true"
			start-in-private="true">
			<capability name="SEARCH_ALL_WINDOWS" value="true" />
			<script><![CDATA[
                import com.workfusion.studio.rpa.recorder.api.internal.representation.*
                import com.workfusion.studio.rpa.recorder.api.*
                import com.workfusion.studio.rpa.recorder.api.types.*
                import com.workfusion.studio.rpa.recorder.api.custom.*
                import static com.workfusion.studio.rpa.recorder.api.RandomValues.CharacterSet.*
                
                // custom imports
                import groovy.json.JsonSlurper
 
				// Mapping the variables
				@CustomScriptAction(
					input = ['bearer_token', 'organisation_id', 'project_id', 'files'],
					output = 'json'
				)
 				
 				// Sending the files
 				def customScript() {
				    // define url
				    def url = "https://x.y.com/gql/api/organisations/" + organisation_id + "/projectId/" + project_id + "/process"
				    // create global json parser
				    def slurper = new JsonSlurper()
				    // define global response
				    def response
				    // Setup post request
				    def postConnection = new URL(url)
				    HttpURLConnection http = (HttpURLConnection) postConnection.openConnection()
				    http.setRequestProperty("Authorization", "Bearer " + bearer_token)
				    http.setRequestProperty("Content-Type", "multipart/form-data")
				    http.setDoOutput(true)
				    http.setRequestMethod('POST')
				    // TODO: create multipart and send as content
				    def multipart
				    // add each file as a filestream to the multipart
				    try{
				        files.each {
				            //
				            def content = new FileInputStream(new File(it))
				            def name = getName(it)
				            content.setRequestProperty(getContentType(name))
				            multipart.addBinaryBody("files", content , name)
				        }
				        // TODO: write away the multipartContent as bytestream?
				        http.getOutputStream().write(multipart)
				        def responseCode = http.getResponseCode()
				        // check if succesfull, if not throw error and catch inside recording
				        if(responseCode >= 200 && responseCode < 300) {
				            response = http.getInputStream().getText()
				        } else {
				            json = "Something went wrong during the upload process"
				            throw new Exception("Something went wrong during the upload process")
				        }
				    } catch(exception) {
				        json = exception.message
				        throw new Exception(exception.message)
				    }
				    // TODO: parse uploadId (don't have any experience with slurper)
				    String upload_id = slurper.parseText(response).uploadId
				    // start polling for the result of the get request
				    def polling = true
				    def counter = 1
				    def getConnection = new URL(url + "/" + upload_id).openConnection()
				    def getResponse
				    def parsedJson
				    do {
				        getResponse = getConnection.getInputStream().getText()
				        def responseCode = getConnection.get
				        // TODO: parse response (slurper <--> class based)?
				        parsedJson = slurper.parseText(getResponse)
				        switch(parsedJson.status) {
				            case "DONE":
				                polling = false;
				                break
				            case "DOCUMENT_CLASSIFICATION_INTERVENTION":
				            case "ENTITY_EXTRACTION_INTERVENTION":
				                throw new Exception("Intervention needed")
				            case "FAILED":
				                throw new Exception("Something went wrong during the processing process")
				            default:
				                counter++
				                // Sleep for 7 seconds before resending the request.
				                Thread.sleep(7000)
				                break
				        }
				    } while(polling && counter <= 150)
				    // put json into table variable
				    String[] columnNames = new String[] {"EntityName", "Confidence", "Theshold"}
				    List<Object[]> temp = new ArrayList();
				    parsedJson.documents.each {
				        def threshold = it.documentType.threshold
				        it.entities.each {
				            Object[] row = new Object[3];
				            row[0] = it.entityType.name
				            row[1] = it.confidence
				            row[2] = threshold
				            temp.add(row)
				        }
				    }
				    Object[][] json = new Object[temp.size()][]
				    for (int i = 0; i < temp.size(); i++) {
				        json[i] = temp.get(i)
				    }
				}
 				
 				def getContentType(String name){
				    def splitName = name.split(".")
				    def extension = splitName[1]
				    switch (extension) {
				        case "pdf":
				            return "application/pdf";
				        case "png":
				            return "image/png";
				        case "doc":
				            return "application/msword";
				        case "docx":
				            return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
				        case "txt":
				            return "text/plain";
				        case "tif":
				            return "image/tif";
				        case "jpg":
				            return "image/jpg";
				        case "rtf":
				            return "application/rtf";
				        // default == not supported type, we don't set content type
				        default:
				            return "";
				    }
				}
				def getName(String path) {
				    // Java equivalent of \\
				    def splitPath = path.split("\\\\")
				    return splitPath[splitPath.length - 1]
				}
  
            ]]></script>
		</robot>
	</robotics-flow>
	<export include-original-data="true" />
</config>

used in this recording:
image