Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imtrinity94/5c1abff04a4769ebc92c94f501eeb64b to your computer and use it in GitHub Desktop.
Save imtrinity94/5c1abff04a4769ebc92c94f501eeb64b to your computer and use it in GitHub Desktop.
Upload Workflow as Multipart/form-data to vRO using vRO JavaScript
/* 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