Hi, I am trying to integrate RB with the OneAll services held at www.oneall.com. They are a middleware to a lot of social media sites connecting with either OAuth 1 or OAuth 2.
I want to use rbv_api.sendHttpGet to authenticate the user server side against the system and then do something with the returned JSON but I cant find a way to add basic authentication to the header?
Authenticating with your API Credentials
You have to use HTTP Basic Authentication to confirm your identity via the API. All requests must come over SSL/HTTPS, and have to be sent to the Site Domain.
In java it would be something like:
// Setup connection
URL url =
new
URL (resource_uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// Connect using basic auth
connection.setRequestMethod(
"GET"
);
connection.setRequestProperty(
"Authorization"
,
"Basic "
+ encoded_site_authentication);
connection.setDoOutput(true);
connection.setReadTimeout(10000);
connection.connect();
connection.getInputStream();
StringBuilder sb =
new
StringBuilder();
String line = null;
You can use rbv_api.sendJSONRequest() API
Use method as GET and set Body as Null and pass username and password or directly use headers to set Basic Auth Header
http://documentation.progress.com/output/Rollbase/index.html#page/rb/rbv-api.sendjsonrequest().html
Hi Anoop, thanks for your response. I have done the following:
var publicKey = '114696e7'; var privateKey = '701489da-'; var url = "https://subdomain.api.oneall.com/connections.json"; var data = null; var method = "GET"; var contentType = "application/json; charset=UTF-8"; var username = "114696e7"; var password = "701489da-"; //var header = "Authorization", "Basic " + encodedSiteAuth); var request = rbv_api.sendJSONRequest(url, data, method, contentType, username, password); rbv_api.println(request);
And when i go to debug I get this:
Error Can't find method com.rb.core.services.api.ServerSideAPI.sendJSONRequest(string,null,string,string,string,string). (line #14) in formula:
var request = rbv_api.sendJSONRequest(url, data, method, contentType, username, password, null);
Please pass null for headers.
Hi Anoop, thanks for your response. I have done the following:
var publicKey = '114696e7';
var privateKey = '701489da-';
var url = "https://subdomain.api.oneall.com/connections.json";
var data = null;
var method = "GET";
var contentType = "application/json; charset=UTF-8";
var username = "114696e7-832d-42d2-8003-8a07e0a25582";
var password = "701489da-532f-4e6f-a68b-23a48f70e9a2";
//var header = "Authorization", "Basic " + encodedSiteAuth);
var request = rbv_api.sendJSONRequest(url, data, method, contentType, username, password);
rbv_api.println(request);
And when i go to debug I get this:
Error Can't find method com.rb.core.services.api.ServerSideAPI.sendJSONRequest(string,null,string,string,string,string). (line #14) in formula:
Flag this post as spam/abuse.
Thanks Murali, I have the following code using a base64 encode function:
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; function encode64(input) { input = escape(input); var output = ""; var chr1, chr2, chr3 = ""; var enc1, enc2, enc3, enc4 = ""; var i = 0; do { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); chr1 = chr2 = chr3 = ""; enc1 = enc2 = enc3 = enc4 = ""; } while (i < input.length); return output; } var publicKey = '114696e7'; var privateKey = '701489da-'; var siteAuth = publicKey + ":" + privateKey; //var encodedSiteAuth = encode64(siteAuth); var encodedSiteAuth = 'MTE0Njk2ZTctODMyZC00MmQyLTgwMDMtOGEwN2UwYTI1NTgyOjcwMTQ4OWRhLTUzMmYtNGU2Zi1hNjhiLTIzYTQ4ZjcwZTlhMg=='; var url = "https://orbis.api.oneall.com/connections.json"; var data = null; var method = "GET"; var contentType = "application/json; charset=UTF-8"; var header = "Authorization: Basic " + encodedSiteAuth; var request = rbv_api.sendJSONRequest(url, null, method, contentType, null, null, header); rbv_api.println(request);
I am getting the error:
Error Wrapped java.lang.NullPointerException (line #52) in formula:
If I null the header and add the username and password I get an unauthorised error
var header = { "Authorization” : “Basic " + encodedSiteAuth }
Optional array of HTTP headers in name/value pairs, by default null
Thanks Murali, I have the following code using a base64 encode function:
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64(input) {
input = escape(input);
var output = "";
var chr1, chr2, chr3 = "";
var enc1, enc2, enc3, enc4 = "";
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
keyStr.charAt(enc1) +
keyStr.charAt(enc2) +
keyStr.charAt(enc3) +
keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
return output;
}
var publicKey = '114696e7';
var privateKey = '701489da-';
var siteAuth = publicKey + ":" + privateKey;
//var encodedSiteAuth = encode64(siteAuth);
var encodedSiteAuth = 'MTE0Njk2ZTctODMyZC00MmQyLTgwMDMtOGEwN2UwYTI1NTgyOjcwMTQ4OWRhLTUzMmYtNGU2Zi1hNjhiLTIzYTQ4ZjcwZTlhMg==';
var url = "https://orbis.api.oneall.com/connections.json";
var data = null;
var method = "GET";
var contentType = "application/json; charset=UTF-8";
var header = "Authorization: Basic " + encodedSiteAuth;
var request = rbv_api.sendJSONRequest(url, null, method, contentType, null, null, header);
rbv_api.println(request);
I am getting the error:
Error Wrapped java.lang.NullPointerException (line #52) in formula:
If I null the header and add the username and password I get an unauthorised error
Flag this post as spam/abuse.
You should pass username and password un-encoded and header as null
var url = "orbis.api.oneall.com/connections.json";
var data = null;
var method = "GET";
var contentType = "application/json; charset=UTF-8";
var request = rbv_api.sendJSONRequest(url, null, method, contentType, <username>, <password>, null);
Thanks Murali, worked a charm
Anoop, the creds needed to be passed in the header :-)
var publicKey = 'guest';
var privateKey = 'guest';
var url = "localhost:15672/
var data = null;
var method = "GET";
var contentType = "application/json; charset=UTF-8";
var username = "guest";
var password = "guest";
var header = { "Authorization” : “Basic " + Z3Vlc3Q6Z3Vlc3Q=} ;
var request = rbv_api.sendJSONRequest(url, data, method, contentType, username, password,header);
rbv_api.println(request);
Error missing : after property id (line #11) in formula:
This is the error that i'm getting
Is Z3Vlc3Q6Z3Vlc3Q= a variable or a string?
002 var publicKey = 'guest';
003 var privateKey = 'guest';
004 var siteAuth = publicKey + ":" + privateKey ;
005 var encodedSiteAuth = 'Z3Vlc3Q6Z3Vlc3Q=';
006 var url ="localhost:15672/.../publish"
007 var data = "null";
008 var method = "POST";
009 var contentType = "application/json; charset=UTF-8";
010 var username = "guest";
011 var password = "guest";
012 var header = { "Authorization” : “Basic " + encodedSiteAuth };
013 var request = rbv_api.sendJSONRequest(url, data, method, contentType, username, password);
014 rbv_api.println(request);
Error missing : after property id (line #13) in formula:
Make your username and password null since you are using basic auth.
Then add the header parameter to the sendjsonrequest call.
Hope this helps
001
002 var publicKey = 'guest';
003 var privateKey = 'guest';
004 var siteAuth = publicKey + ":" + privateKey ;
005 var encodedSiteAuth = 'Z3Vlc3Q6Z3Vlc3Q=';
006 var url ="localhost:15672/.../publish";
007 var data = null;
008 var method = "POST";
009 var contentType = "application/json; charset=UTF-8";
010 var username = null;
011 var password = null;
012 var header = { "Authorization” : “Basic " + encodedSiteAuth };
013 var result = rbv_api.sendJSONRequest(url,data,method,contentType,username,password,headers);
Error missing : after property id (line #13) in formula
Still Getting the same error - after making the mentioned changes.
That's weird.
Instead of null try empty strings ''
Also, are you performing this in the public cloud? Or a private cloud?
Thanks for your help. I have now made a public rabbitMQ instance available for troubleshooting.
The code that i am using now:
var url ="ec2-54-172-14-24.compute-1.amazonaws.com:15672/.../publish";
var data = {"routing_key":"queue_test",
"payload":"message test ",
"payload_encoding":"string"};
var method = "POST";
var contentType = "application/json; charset=UTF-8";
var username = "guest";
var password = "guest";
var encodedSiteAuth = "Z3Vlc3Q6Z3Vlc3Q=";
var headers ={ "Authorization" : "Basic " + encodedSiteAuth };
var headers ="";
var result = rbv_api.sendJSONRequest(url,data,method,contentType,username,password,headers);
015 rbv_api.println(result);
However, I am still getting the following error:
HTTP Error 400: HTTP call failed: Bad Request (line #15)
What do you think?
Your url needs http or https
Then try using headers (basic auth) and null username and pass.
Hope this helps
Thanks for the help again, I've tried what you have mentioned but I'm getting the same error -
HTTP Error 400: HTTP call failed: Bad Request (line #15)