on 09-10-2018 1:26 PM
Hello Colleagues,
I was experimenting SAP Translation HUB Api(https://saptranslation-s001*****9trial.hanatrial.ondemand.com/translationhub/api/v1/translate), Trace also not helping for xsjs.
i am getting empty array response. i have no idea where things go wrong.
Please help me here.
Initial tests with postman:
Authentication type : Basic
Content: Application/Json.
no csrf set and i get response succesfully.
Now in XSJS
i create destination file
description = "Translator";
host = "saptranslation-s001961**9trial.hanatrial.ondemand.com";
port = 80;
pathPrefix = "/translationhub/api/v1/";
//proxyType = none;
useProxy = true;
proxyHost = "proxy";
proxyPort = 8080;
authType = basic;
useSSL = false;
timeout = 3000;
In the XSADMIN i supplied the required username and password.
My XSJS Code
(Code 1)(Webrequest)
var dest = $.net.http.readDestination("translationPackage.xs.xsdestination", "translator");
var client = new $.net.http.Client();
//Make Request
var data = {
"targetLanguages": [
"fr"
],
"sourceLanguage": "en",
"enableMT": true,
"enableTranslationQualityEstimation": true,
"domain": "string",
"companyMLTRId": "string",
"units": [
{
"textType": "string",
"key": "string",
"value": "Love is great",
"searchData": {
"language": "string",
"value": "string"
}
}
]
};
var jdata = JSON.stringify(data);
var req = new $.web.WebRequest($.net.http.POST, '/translate');
req.headers.set("Content-Type", "application/json");
req.setBody(jdata);
client.request(req, dest);
var response = client.getResponse();
$.response.contentType = "application/json";
$.response.status = $.net.http.OK;
$.response.setBody(JSON.stringify(response));
(Code 2)(http)
var data = {
"targetLanguages": [
"fr"
],
"sourceLanguage": "en",
"enableMT": true,
"enableTranslationQualityEstimation": true,
"domain": "string",
"companyMLTRId": "string",
"units": [
{
"textType": "string",
"key": "string",
"value": "Love is great",
"searchData": {
"language": "string",
"value": "string"
}
}
]
};
var jdata = JSON.stringify(data);
var dest = $.net.http.readDestination("translationPackage.xs.xsdestination", "translator");
var client = new $.net.http.Client();
function doPOST() {
try {
var req = new $.net.http.Request($.net.http.POST, "translate");
req.contentType = "application/json";
req.setBody(jdata);
client.request(req, dest);
var response = client.getResponse();
var res = JSON.stringify(response);
$.response.contentType = "application/json";
$.response.status = $.net.http.OK;
$.response.setBody(JSON.stringify(res));
} catch (err) {
$.response.contentType = "text/plain";
$.response.setBody("Error while executing query: [" + err.message + "]");
$.response.returnCode = 200;
}
}
doPOST();
Both of the code returns empty array { } as result.
Please tell me how to fix.
Thanks a lot.
Br,
Gabriel
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.