- 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-12-2017 10:44 PM
where did you pass the client_id and client_secret?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 11:19 PM
Hi Harsh,
This is how i have created rest message for google api.
If we go to the url :http://maps.googleapis.com/maps/api/geocode/json?address=india ,we will get some json response.
To integrate this i have done the following steps
and i am using it as
var requestBody;
gs.print("start");
var responseBody;
var status;
var sm;
try{
sm = new sn_ws.RESTMessageV2("google map", "get");
gs.print("start1");
response = sm.execute();
gs.print("start2");
var jsonString = response.getBody();
gs.print(jsonString);
gs.print("start3");
var parsed = JSON.parse(jsonString);
gs.print("start4");
gs.print('result1' + parsed.result[0].field_name_1);
gs.print('result2' + parsed.result[0].field_name_2);
and response is null,
so error is
*** Script: start
*** Script: start1
java.lang.IllegalArgumentException: host parameter is null
*** Script: start2
*** Script:
*** Script: start3
Am i setting it wrongly (refer screenshots)? or using it wrongly in script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 11:31 PM
Hi Megha,
The endpoint for the REST message "google map" get is missing "https://"
If you add it and retest - all will be well!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 11:41 PM
Hi anthony ,
Thank you .It worked. now without any authentication it worked. I have to integrate some api , by authenticating Oauth token. I have gone through the links that Shishir and harsh mentioned about Oauth profile.
Why should we do those steps cant we just set Auth token and get the response.?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2017 11:57 PM
Hi Megha,
if you want to use Oauth then you must be aware of your client id and client session and based on that it will generate a token.
i am not sure about https://google.map . i had tested between two instance and i was able to achieve it.
i also tried with slack and service-now integration by using oauth then in that case i had used slack client session and slack client id to generate the token.
