Running a Rest message from scheduled job

Neha Agarwal
Giga Expert

I have a rest message with POST method, rest message is running and giving result in test run. but when I am trying to run this using scheduled job it gives me error.

I wrote this:

var r = new sn_ws.RESTMessageV2('RestMessage','post');

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

var parser = new global.JSONParser();

var parsed = parser.parse(responseBody);

I get the error:

REST Msg Outbound - RESTMessageClient : Error constructing REST Message/Method: global.legalholdpro/post: com.glide.generators.InvalidGlideRecordException: REST message/method 'global.legalholdpro/post' not found in table 'sys_rest_message_fn': com.glide.rest.outbound.RESTMessageDAO.getMethodRecord(RESTMessageDAO.java:97)
com.glide.rest.outbound.RESTMessageDAO.<init>(RESTMessageDAO.java:72)
com.glide.rest.outbound.RESTMessageDAO.newInstance(RESTMessageDAO.java:67)

also I need to push the results which is in JSON format in a staging form, which will work after rest gets executed. Please suggest?

 

1 ACCEPTED SOLUTION

This worked for me:

 

var Url = 'https://www.testurl.com/';

var request = new sn_ws.RESTMessageV2();

request.setHttpMethod('post');

request.setEndpoint(Url);

request.setRequestHeader("Content-type",'application/json');

request.setRequestHeader("Authorization",'Bearer YYNp0IIJozbzfUV9');

var response = request.execute();

var httpResponseStatus = response.getStatusCode();

var httpResponseContentType = response.getHeader('Content-Type');

//Debug the results:

gs.debug("http response status_code: " + httpResponseStatus);

gs.debug("http response content-type: " + httpResponseContentType);

View solution in original post

8 REPLIES 8

If it is in scoped app then it should be called via scoped app name to the REST Message.

Also check if your post http method is defined in the related rest message.

 

It is in global scope, I tried using global.restmsg name also but didn't work.

Divya157
Kilo Explorer

Can someone help me with the scrip for the use scheduled job to trigger your REST message in the POST method.

This worked for me:

 

var Url = 'https://www.testurl.com/';

var request = new sn_ws.RESTMessageV2();

request.setHttpMethod('post');

request.setEndpoint(Url);

request.setRequestHeader("Content-type",'application/json');

request.setRequestHeader("Authorization",'Bearer YYNp0IIJozbzfUV9');

var response = request.execute();

var httpResponseStatus = response.getStatusCode();

var httpResponseContentType = response.getHeader('Content-Type');

//Debug the results:

gs.debug("http response status_code: " + httpResponseStatus);

gs.debug("http response content-type: " + httpResponseContentType);