invite Collaborators from Salesforce API
回答済みHi,
We are trying to access BOX collaborators using Salesforce API.
HttpRequest req = new HttpRequest();
endPointURL='https://api.box.com/2.0/collaborations';
req.setEndpoint(endPointURL);
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
req.setHeader('Authorization','Bearer '+Authcode);
String payload='';
payload=payload+'{';
payload=payload+'"item":';
payload=payload+'{';
payload=payload+'"id":'+ folderNameToIdMap.get(usrRoleNameMap.get(UserInfo.getUserRoleId()))+',' ;
payload=payload+'"type": "folder"';
payload=payload+'},';
payload=payload+'"accessible_by":';
payload=payload+'{';
payload=payload+'"login":'+'"***email address removed for privacy***"'+',';
payload=payload+'"type": "user"';
payload=payload+'},' ;
payload=payload+'"role": "editor"';
payload=payload+'}';
System.debug('--------->>'+payload);
req.setbody(payload);
Http http = new Http();
HTTPResponse res = http.send(req);
We are getting error 401 (unauthorized) if i use the above code. Kindly help us to resolve this issue.
Regards,
Niranjan
-
Hey ,
If you are receiving a 401 unauthorized as the API response I would check your token to make sure it has not expired. One more thing I would like to add is although creating the HTTP request manually is totally fine I would use our Box Salesforce SDK found here
You can find the call to add a collaborator here
By ID:
BoxCollaborator user = new BoxUser(api, 'user-id') BoxFolder folder = new BoxFile(api, 'folder-id'); folder.collaborate(user, BoxCollaboration.Role.EDITOR);
By Email:
BoxFolder folder = new BoxFile(api, "id"); folder.collaborate("gcurtis@box.com", BoxCollaboration.Role.EDITOR);
サインインしてコメントを残してください。
コメント
1件のコメント