- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2017 10:44 PM
Hi ,
I am getting the response when i use curl command
curl -H 'Accept: application/json' -H 'Content-Type:application/json' -XGET https://someapi.example -H 'authorization:token' , for this I am getting the response.
But when i use it in javascript as following,
var r = new RESTMessage('https://someapi.example', 'get');
r.setStringParameter('token', 'token');
var response = r.execute();
var jsonString = response.getBody();
var parser = new JSONParser();
var parsed = parser.parse(jsonString);
getting error as:org.mozilla.javascript.EcmaError: Cannot convert null to an object.
am i missing anything?
The response here is null.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2017 02:14 AM
Hey,
This worked for me,
var requestBody;
gs.print("start");
var responseBody;
var status;
var sm;
try{
sm = new sn_ws.RESTMessageV2("test", "get");
gs.print("start1");
sm.setRequestHeader("Authorization","token-string");
response = sm.execute();
gs.print("start2");
var jsonString = response.getBody();
Thank you all for your response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 12:27 AM
And also i tried inserting a record in rest messge table and tried as
var requestBody;
gs.print("start");
var responseBody;
var status;
var sm;
try{
sm = new sn_ws.RESTMessageV2("test", "get");
gs.print("start1");
sm.setAuthenticationProfile('oauth2', 'token');
gs.print("start2");
response = sm.execute();
var jsonString = response.getBody();
var parser = new JSONParser();
var parsed = parser.parse(jsonString);
gs.print("parsed");
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
} catch(ex) {
responseBody = ex.getMessage();
status = '500';
} finally {
requestBody = sm ? sm.getRequestBody():null;
}
it is printing gs.print("start1"); ,and not start2. stopped in sm.setAuthenticationProfile('oauth2', 'token');
I am getting nothing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 12:32 AM
i am not getting where to define token in that ,sm.setAuthenticationProfile('oauth2', 'token'); this one is sysid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 12:32 AM
Please add var in below line and try
var sm = new sn_ws.RESTMessageV2("test", "get");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 12:35 AM
Hi Shishir,
its already there,
var sm;
try{
sm = new sn_ws.RESTMessageV2("test", "get");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 12:38 AM
oh yes, sorry I missed to notice.
