- 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 03:12 AM
for now i am not requesting any token , i have the token
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 03:29 AM
setAuthenticationProfile('oauth2', '<pass oauth profile sys id >');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 03:36 AM
Hi Harsha,
setAuthenticationProfile('oauth2', '<pass oauth profile sys id >');
for this i should create oauth2 record in table , but where should i specify the token .I don't know what to fill in that form, mainly provider and where will token comes into picture.
I think that is for get token. can you explain me clearly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 03:44 AM
Hi Megha,
have you checked this blog ?
How to setup OAuth2 authentication for RESTMessageV2 integrations
if you want to build token based integration then you must need to create application registry and then here you can select that in oauth provider field.
Set the credentials for the REST message using an existing basic auth or OAuth 2.0 profile.
| Name | Type | Description |
|---|---|---|
| type | String | The type of authentication profile to use. Valid values are 'basic' to use basic authentication, or 'oauth2' to use OAuth 2.0. |
| profileId | String | The sys_id of an authentication profile record. When using basic auth, specify the sys_id of a Basic Auth Configuration [sys_auth_profile_basic] record. When using OAuth 2.0, specify the sys_id of a OAuth Entity Profile [oauth_entity_profile] record. |
RESTMessageV2 - setAuthenticationProfile(String type, String profileId)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 10:32 PM
Hi Shishir and Harsh,
I went through the link you both suggested.To set the third party Oauth provider we should have client id and secret.In that link they have created those in different instance as Oauth for consumer, and using it in different instance as provider.
In my case I just have an API and I need to get some data, by providing token.
I have also follow the steps as they have done it for Yahoo finance in service now, but its not working.
And my first script also
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.
Is the script incorrect?
Is there a way that i can use curl command directly?
