Skip to Content

XSJS - POST HttpRequests to external not working


I am trying to send an email from XSJS using HttpRequest POST method. I am trying from a month, googling, searching on sap answers portal but still could not get it working.

This is a working instance from Postman which I want to integrate with XSJS.

I tried to get this done with multiple ways, the last one is this:

var req =new $.net.http.Request($.net.http.POST,"/xxxx/xxxxx/sendmail.php");

var entity = req.entities.create();
req.contentType = "multipart/form-data";

body = body + "Content-Disposition: form-data; toEmail=\"\"\r\n";
body = body + "Content-Disposition: form-data; subject=\"Sample Email test\"\r\n";
body = body + "Content-Disposition: form-data; rawBody=\"Raw Text body\"\r\n";
body = body + "Content-Disposition: form-data; htmlBody=\"<p>HTML Body</p>\"\r\n";
body = body + "Content-Disposition: form-data; key=\"myapikey\"";
entity.headers.set("Content-Disposition", "form-data; toEmail=\"\"\r\n");
 entity.headers.set("Content-Disposition", "form-data; subject=\"Sample Email test\"\r\n");
entity.headers.set("Content-Disposition", "form-data; rawBody=\"Raw Text body\"\r\n");
entity.headers.set("Content-Disposition", "form-data; htmlBody=\"<p>HTML Body</p>\"\r\n");
entity.headers.set("Content-Disposition", "form-data; key=\"myapikey\"\r\n");
  var clientresponse = client.request(req, dest).getResponse();
  $.response.status = $.net.http.OK;

And this is how it is flowing if we run from cURL:

curl -X POST \
  http://aabbccddeeff/xxxx/yyyy/sendmail.php \
  -H 'Cache-Control: no-cache' \
  -H 'Postman-Token: ec19e174-ac78-f9a7-ade6-cef762b4e53f' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F \
  -F 'subject=Test Mail' \
  -F 'rawBody=This is test mail' \
  -F 'htmlBody=<p>This is <strong>test</strong> mail.<p>' \
  -F 'myapikey'

It keeps on giving me error message as Payload is empty. The endpoint is based on PHP and it says

die("Payload is empty")

Need help from SAP experts.



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

  • Get RSS Feed

1 Answer

  • Feb 12, 2018 at 09:07 PM

    Also - I am not sure if you are only using PHP to send emails, but you can configure your HANA/XS instance to do the same. If you are interesting, check out this GIST:

    Add comment
    10|10000 characters needed characters exceeded