Skip to Content
avatar image
Former Member

Get call using POST operation XSJS

Hi ,

I need to create a get service which have 10 filter parameter so I am going for post operation , when I try to create it ,it showing me 500 error req-body undefined.

//

var ReqBody = $.request.body.asString();

ReqBody = JSON.parse(ReqBody);

var pstmt;

var rs;

var PRHeader_query;

var output = {};

var conn = $.db.getConnection();

PRHeader_query = ' select OBLIGATION_ID, ENTITY_ID, from "OBLIGATION"."OBLIGATION" WHERE 1=1 ';

//pstmt.setObject(1,(ReqBody.obligation_id)); //$.response.setBody("sumit"); if(ReqBody.obligation_id )

{ ReqBody.obligation_id = decodeURIComponent(ReqBody.obligation_id );

PRHeader_query = PRHeader_query +" and OBLIGATION_ID='" + ReqBody.obligation_id +"'"; }

pstmt = conn.prepareStatement(PRHeader_query);

rs = pstmt.executeQuery();

var res = [];

while (rs.next())

{ output = {}; output.obligation_id = rs.getString(1);

output.entity_id = rs.getString(2);

res.push(output); }

rs.close();

pstmt.close();

conn.close();

var resp = JSON.stringify({allData :res});

$.response.setBody(resp);

//

Please help me on this .

Thanks,

Sumit

Add comment
10|10000 characters needed characters exceeded

  • Former Member

    Hi Florian ,

    I am calling the service using postman . find bellow details .

    Method : Post ,

    Headres :

    1)Content-Type - application/json

    2)[{"key":"Authorization","value":"Basic UDE5NDMyNjgxMTM6U3VtaXRAMTIzNDU="

    Body

    { "obligation_id":"2017.01.02.0001" }

    Authorization (Basic)

    username : XYZ

    password : 1234

    Thanks,

    Sumit

  • If you do it in that way, than it should work. Can you share a screenshot of Postman to show the exact config?

  • Maybe you can add the information how you call your xsjs service and how you set the parameters you expect in the request body.

    Regards,
    Florian

  • Get RSS Feed

1 Answer

  • Mar 19 at 04:38 PM

    Hello Sumit,

    My 2 cents:

    1. It is not right to use/implement POST method to retrieve the data. This is against what RESTful Architecture preach us.

    2. Since there is no heavy/complex business logic, why don't you try and implement the GET as a XSODATA service(that provides system query options like $filter on any exposed attributes)? Here is a tutorial on creating a simple XSODATA based service.

    Good luck!

    Add comment
    10|10000 characters needed characters exceeded