Skip to Content

POSTING a ZIP file to REST API using Outbound XSJS service

Aug 28, 2017 at 11:53 AM


avatar image
Former Member


I was trying to call a REST API ( that accepts a ZIP file and a string as form-data, below is my code,

try { 
var destination = $.net.http.readDestination("package", "httpdestfile"); 
var client = new $.net.http.Client(); 
var zip = new $.util.Zip(); 
zip["file1.txt"] ='The file contains this data'; 
zip["file2.txt"]='the second file containing the data'; 
var req = new $.net.http.Request($.net.http.POST,"");

req.setBody(JSON.stringify("options":{ "numTopics":2, "numTopicsPerDoc":1, "numKeywordsPerTopic":5 }));

var resp = client.request(req, destination).getResponse();
try{ myBody = JSON.parse(resp.body.asString()); 
{ myBody = resp.body.asString(); 
$.response.contentType = "application/json"; 
$.response.setBody(JSON.stringify({"body" : myBody , "Headers" : myHeader })); 
catch (e) 
$.response.setBody(e.message); $.response.status = $.net.http.INTERNAL_SERVER_ERROR; 

i was able to set the headers for the REST service but not the body as setBody doesn't seem to work,Also i was trying to create a zip file in the same xsjs code and post it to the rest service

I have attached the snap of the output that i get after executing the above code, you can see that even if i pass "options" using setBody, the message says options are missing,

Can any one please help on acheiving this.



capture.png (62.1 kB)
10 |10000 characters needed characters left characters exceeded

Do you get any errors or something else which let you "assume" that it does not work? If yes, please add the information to your question.


Former Member

Hi Florian,

I have added few more details and have attached a snap specifying the error

Let me know if i need to add any more details

Thanks ,


* Please Login or Register to Answer, Follow or Comment.

0 Answers