Skip to Content
0
Jul 05, 2019 at 10:15 AM

Calling SAP Gateway Service through Ajax on the SAP HANA Web-based Development Workbench

395 Views

I have set-up a Gateways Service through transaction SEGW on SAP. I also made a trial HANA Web Based Development Workbench through the SAP Cloud Platform. In this HANA workbench I have an xsjs file that I am trying to use to get data from my service. This xsjs file is acting as a middle layer between my gateway service and a chatbot built through SAP Conversational AI. However, I am experiencing a 500 error when trying to run my xsjs file.

I am trying to call my gateway service through a ajax call to the service URL. I have checked and can confirm the URL is correct. I have also tried removing the ajax call and just hardcoding a test response and this works, my chatbot recieves this response data, therefore, there must be something wrong with my ajax call.

var output;switch($.request.method){case $.net.http.POST:var body;

        $.ajax({
            url:"myserviceurl",
            type:'GET',
            datatype:'json',
            success:function(oResult){
                output ={"replies":[{"type":"text","content":"Success"}],"conversation":{"language":"en","memory":{"user":"Bob"}}};
                body = JSON.stringify(output);
                $.response.contentType ='application/json';
                $.response.setBody(body);
                $.response.status = $.net.http.OK;},
            error:function(error){
                output ={"replies":[{"type":"text","content":"Error"}],"conversation":{"language":"en","memory":{"user":"Bob"}}};

                body = JSON.stringify(output);
                $.response.contentType ='application/json';
                $.response.setBody(body);
                $.response.status = $.net.http.OK;}});}

I expected to see a response with the content 'Error' or 'Success' but I get neither and can see a 500 error is being thrown.

Any help would be greatly appreciated.

Kind Regards,

Joe