You need to sign in to do that
Don't have an account?
Nagaraj SV
Salesforce to OneHub Integration?
I am trying to push image from salesforce to ONEHUB .But i am getting ERROR .
Can any have idea to how to do integration with One hub.
Please help me
You can try using the pre-built connector from https://www.itduzzit.com/connect/onehub-to-salesforce, or we can try to help with a custom APEX interface if you post your code and the ERROR you are getting.
Thank for quick response.
Vf page :
<apex:page controller="Onehubcntr">
<apex:form >
<apex:pageblock title="Get&Post the File in ONE HUB">
<apex:inputText value="{!GetFile1}" title="GetFile1"/>
<br/>
<br/><apex:inputFile style="width:100%" id="fileToUpload" value="{!fileBody}" filename="{!fileName}" />
<apex:commandbutton action="{!getSFDCSessionID}" value="PUTFILE"/>
</apex:pageblock>
<iframe src="data:image/gif;base64,{!Pdffile}"></iframe>
</apex:form>
</apex:page>
Controller:
public class Onehubcntr{
public string fileName{get;set;}
public Blob fileBody{get;set;}
public static string attachid;
//Fetched from URL
String code ;
public String GetFile1{get;set;}
public static String AccessToken1;
public transient String Pdffile{get;set;}
public Onehubcntr (){
code = ApexPages.currentPage().getParameters().get('code') ;
//Get the access token once we have code
if(code != '' && code != null){
system.debug('>>>>>>>>>>>>>>>>.....code'+code);
getOneHubToken();
}
}
public class WrapperAuth{
String access_token{get;set;}
String token_type{get;set;}
String uid{get;set;}
public WrapperAuth(){
}
}
public pagereference getSFDCSessionID(){
PageReference pg = new PageReference('https://ws-api.onehub.com/oauth/authorize?response_type=code&client_id=8roys5vt6f5lbbkkih2x2g50dijp3u0&client_secret=5eoy8diy38wou36hettaj8k4enrl2gv&username=venkatanagarajas@gmail.com&password=Spiderman@57&redirect_uri=https://c.ap2.visual.force.com/apex/OnehubPage') ;
return pg ;
}
public void getOneHubToken(){
String tokenuri = 'https://ws-api.onehub.com/oauth/token?grant_type=authorization_code&client_id=8roys5vt6f5lbbkkih2x2g50dijp3u0&redirect_uri=https://c.ap2.visual.force.com/apex/OnehubPage&code='+code;
//String tokenuri = 'https://ws-api.onehub.com/oauth/token?grant_type=password&client_id=8roys5vt6f5lbbkkih2x2g50dijp3u0&client_secret=5eoy8diy38wou36hettaj8k4enrl2gv&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxIntegration&code='+code;
HttpRequest req = new HttpRequest();
req.setEndpoint(tokenuri);
req.setMethod('POST');
req.setTimeout(60*1000);
Blob headerValue = Blob.valueOf('8roys5vt6f5lbbkkih2x2g50dijp3u0' + ':' + '5eoy8diy38wou36hettaj8k4enrl2gv');
System.debug('headerValue====>>>>' + headerValue);
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
System.debug('authorizationHeader======>>>>>>' + authorizationHeader);
req.setHeader('Authorization', authorizationHeader);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
string accessToken;
system.debug('Response=====>>>>'+resp);
if(res.GetStatusCode()== 200){
JSONParser parser = JSON.createParser(resp);
parser.nextToken();
parser.nextValue();
String fieldName = parser.getCurrentName();
accessToken= parser.getText();
getFile(accessToken);
}
System.debug(' You can parse the response to get the access token ::: ' + resp);
}
//public void getFile(string accessToken){}
public void getFile(string accessToken){
System.debug('accessToken=====>>>>>'+accessToken);
attachment a =[select id ,Name,body from attachment where id=:'00P28000001JpboEAC'];
HttpRequest req = new HttpRequest();
req.setEndpoint('https://ws-api.onehub.com/');
req.setMethod('POST');
String username = 'venkatanagarajas@gmail.com';
String password = 'Spiderman@57';
//Blob headerValue = Blob.valueOf();
//Append Basic when we are sending userid and password
// String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
// Append Bearer when we are sending userid and password
req.setHeader('Authorization','Bearer' +accessToken);
req.setHeader('Content-Type','multipart/form-data');
req.setbodyasBlob(a.body);
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
system.debug('Response====>>>>'+res);
system.debug('ResponseBody=====>>>>>'+res.getBody());
}
}
What is the error you are getting?
I have sent an email to Onehub .They will reach me on monday .
I have changed end point from https://ws-api.onehub.com/ to https://ws.onehub.com/workspaces/848421/folders/873366451
Now it is giving Bad request Satus Code:400