Created
February 24, 2023 08:37
Upload Workflow as Multipart/form-data to vRO using vRO JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Inputs | |
* (WorkflowCategory) wf_folder | |
* (string) wf_zip_path | |
* (REST: RESTHost) rest_Host | |
*/ | |
var boundary = System.next UUID(); | |
var crlf "\r\n"; | |
//Generate multipart content | |
var content = ""; | |
content += "--" + boundary + crlf; | |
content += "Content-Disposition: form-data; name=\"file\"; filename=\"mywf.workflow\"" + crif; | |
content += "Content-Type: application/zip" + crlf + crlf; | |
var fr = new FileReader(wf_zip_path); | |
fr.open(); | |
content += fr.readAll() + crlf; | |
content += "--" + boundary + crlf; | |
content += "Content-Disposition: form-data; name=\"categoryId\"" + crlf + crlf; | |
content += System.getObjectId(wf_folder) + crlf; | |
content += "--" + boundary + crlf; | |
content += "Content-Disposition: form-data; name=\"overwrite\"" + crlf + crlf; | |
content += true + crlf; | |
content += "--" + boundary + "--" + crlf; | |
var req = rest_Host.createRequest("POST", "workflows", content) | |
req.contentType = "multipart/form-data; boundary=" + boundary; | |
req.setHeader("Accept", "application/xml"); | |
var reponse = req.execute(); | |
System.log("URL: " + req.fullUrl + " -> " + reponse.statusCode); | |
if (reponse.statusCode != 202) { | |
System.warn("Error during workflow import."); | |
System.log("---- Request ----"); | |
System.log("URL: " + req.fullUrl); | |
System.log("Content:\r\n" + content); | |
System.log(""); | |
System.log(""); | |
System.log("---Response---"); | |
System.log("Status Code: " + reponse.statusCode); | |
System.log("Content: " + reponse.contentAsString); | |
var headers = reponse.getAllHeaders(); | |
for each(var k in headers.keys) { | |
System.log("Header [" + k + "]:" + headers.get(k)); | |
} | |
throw "Error during workflow import (HTTP Code: " + reponse.statusCode + ")"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment