VMware Cloud Community
DexG83
Enthusiast
Enthusiast

REST API POST with YAML Content

Hello Community,

 

I am working with an Orchestrator standalone version 8.6.

In my scenario, I need to update a YAML file in a Git Repo with an Orchestrator Workflow.

I tested all requests in Postman and want to use the code:

 

var data = new FormData();
data.append("branch", "RR_vRO8.6_TEST");

 

Unfortunately I got the following error:

 

2021-11-02 09:03:10.314 +01:00 ERROR Error in (Workflow:Update Config in Git  / Scriptable task (item1)#12759) ReferenceError: "FormData" is not defined.

 

 

I am happy about any idea.
 
Regards,
Dex
 
 
Labels (3)
Tags (3)
Reply
0 Kudos
1 Reply
xian_
Expert
Expert

Hi Dex,

this looks like a multipart/form-data Content-type. I was working on something similar recently, but could not get it working with binary data. YAML is text so the code should work for your usecase. Try to adapt it:

var boundary = System.nextUUID();
var content = "--" + boundary + "\r\n";
content += "Content-Disposition: form-data; name=\"branch\"; filename=\"RR_vRO8.6_TEST\"\r\n";
content += "Content-Type: application/octet-stream\r\n\r\n";
content += file.content + "\r\n\r\n";
content += "--" + boundary + "--\r\n";
var request = targetHost.createRequest("POST", "/api", content);
request.contentType = "multipart/form-data; boundary=" + boundary;
var response = request.execute();

Here file is an MimeAttachment object (uploaded file) and targetHost is your Git REST endpoint (update the URL as necessary).

Let me know how it goes.

Reply
0 Kudos