function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sumant Kuchi 4Sumant Kuchi 4 

box integration api issue

Hi, I recently stepped into SF and working on BOX integration.
Here are the scenarios I used for Box integration.
1) Downloaded box app from appExchange and used two box accounts to setup (I have no clue why do we need user account for developing)
2) followed the instructions what document given.
3) Was uploaded files in box section of an object
But this solution is not sufficient since eveyuser is asked login to grant permissions to create folder

Scenario 2:
1) Downloaded box app from appExchange and used two box accounts to setup (I have no clue why do we need user account for developing)
2) Created custom object which resembles the Attachment object that will replace the standard attachments related list on the page layout.
3) Created VF for file upload page and Controller for that page
4) In the Controller I'll be able to attache files to SF File Storage but I'll not be able to upload to BOX, here is the error and code to box I used.
Error:

13:24:15:149 USER_DEBUG [19]|DEBUG|Toolkit:[AUTH_WRAPPER_PREPARE_FAIL_MESSAGE=Unable to use default credentials to make a callout to box (maybe this is in a trigger or constructor): , authWrapper=BoxAuthWrapper:[adminSettings=box__BoxUser_Settings__c:{}, client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, client_secret=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, redirect_uri=null, resultMessage=, userSettings=box__BoxUser_Settings__c:{}], didAuthChange=false, existingFolderId=null, mostRecentError=, newFolderMetas=(), newFrups=(), newRootFolders=()]



Note: I replaced client_id and client_secrets with x and y respectively
and the box toolkit code I used to upload file..
 
//@future (callout=true)
    private void createAttachmentinBox(id attachmentid){
        System.debug('In HelperClass');
        String BoxFolderid='11476443045';
        box.Toolkit boxToolkit = new box.Toolkit();
        System.debug('boxtoolkit'+boxToolkit);
        Attachment Myattachment=[select name,body,parentid from attachment where id=:attachmentid];
        System.debug('Attachment '+Myattachment);
        String fileFromBoxID=boxtoolkit.createFileFromAttachment(Myattachment,null, BoxFolderid,null);
        System.debug('fileFromBoxID '+fileFromBoxID);
        boxToolkit.commitChanges();
        //delete [select id from Attachment where id=:attachmentid];
    }
Why am I not able to use default credentials to make a callout to box? Could you get me solition for my issue?

I would be appreciated if you could get me solution







 
Onesh ReddyOnesh Reddy
Hi Sumanth,
Your code is perfect, try removing the comment before @future (callout=true) and run the trigger.

Let me know if it helps you.
Regards,
Onesh.K
Sumant Kuchi 4Sumant Kuchi 4
Hi Onesh, thanks for your response. I tried first but still unable to make it to work Thanks, Sumant
Sumant Kuchi 4Sumant Kuchi 4
HI Onesh, I tried it worked... May I know whats the reason just in curiosity. And another request, How do we get the box URL for this file to give it view link on SF?
Onesh ReddyOnesh Reddy
Hello Sumant,
Glad it helped...!
Using @future (callout=true) invokes the box method to upload attachments.(Callout)
To get the Box file URL you have to use REST Api.

Mark it as BEST ANSWER if it helped you, so that it may help others too.

Best Regards,
Onesh.K
Sumant Kuchip 2Sumant Kuchip 2
Thanks for your info...it helped me .. how do I mark it as BEST answer to your questions? since I'm new Im not sure where is that mark but I would like to mark it as best for others.

Could you send the idea to get the Box file URL you have to use REST Api? That would be really awesome if you could provide details on that.

Sumant K
Onesh ReddyOnesh Reddy
Sumant,

You will find the button MARK THIS BEST ANSWER. above my answer (The answer which helped you). Just a Click can mark it best answer.
Im looking into Box file URL using REST Api and will post the links ASAP.
Thanks,
Sumant Kuchi 4Sumant Kuchi 4
I was trying with the following code (googled) but unable to get access_token and refresh _token, how do we get them to Apex public static String downloadBoxFile(String fileId){ //BoxAuthParser bparser = RefreshTokenrequest(); Http h = new Http(); HttpRequest req = new HttpRequest(); string endPointValue = 'https://api.box.com/2.0/files/'; endPointValue=endPointValue+fileId+'/content'; req.setEndpoint(endPointValue); req.setMethod('GET'); //req.setHeader('Authorization', 'Bearer '+bparser.access_token); HttpResponse res = h.send(req); system.debug('pANY'+res.getBody()); return res.getHeader('Location'); }