Skip to Content
avatar image
Former Member

POSTING a ZIP file to REST API using Outbound XSJS service

Hi,

I was trying to call a REST API (http://sandbox.api.sap.com/ml/topicdetection/inference_sync) 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();
if(resp.body) 
try{ myBody = JSON.parse(resp.body.asString()); 
} 
catch(e)
{ 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.

Thanks

Sumeet

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

  • 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 ,

    Sumeet

  • 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.

    Regards,
    Florian

  • Hi Sumeet,

    By any chance did you manage to get the solution for this issue? I am also trying to implement similar use case where I need to post zip file to restful API.

    Regards,

    Manish

  • Get RSS Feed

0 Answers