box / box-salesforce-sdk Goto Github PK
View Code? Open in Web Editor NEWThis is the Salesforce SDK for integrating with the Box Platform.
Home Page: https://developer.box.com/guides/tooling/sdks/salesforce/
License: Apache License 2.0
This is the Salesforce SDK for integrating with the Box Platform.
Home Page: https://developer.box.com/guides/tooling/sdks/salesforce/
License: Apache License 2.0
Resource strings in BoxGroup.cls have a '/' prefix and the base url from BoxApiConnection has a '/' suffix. When joined these generate an invalid url and the request fails.
master
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can resolve this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here is some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
An npm token must be created and set in the NPM_TOKEN
environment variable on your CI environment.
Please make sure to create an npm token and to set it in the NPM_TOKEN
environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/
.
Good luck with your project β¨
Your semantic-release bot π¦π
Hello,
I was wondering if the box team is planning on create a BoxFileUploadSession class as the Java SDK to support upload of large files
Adding support for getting a trashed file
Exposing Box content within 1 or more custom objects in Salesforce may have serious consequences for clients API usage limits. We believe the architecture of this system poses unique challenges for developers, administrators and for Salesforce operations team to track API utilization.
We propose an enhancement which would audit the number updates made to Salesforce Custom Objects and audit the clients usage limit associated with the Salesforce instance. This data would be visible on granular level for analysis. This data could be useful to correlate the changes in the target instance for verifying more complex work flows.
The URL that is returned from BoxFile.getPreviewLink isn't actually a "preview". It's an embed URL that expires after 60 seconds. You can't, for example, create the link and send it in an email (unless the recipient is obsessive about their email and clicks the link immediately).
The naming should be updated to reflect the nature of what is actually returned.
Add a setAsUser method to BoxApiConnection and add the 'as-user' header to BoxApiRequest when sending a request.
Code coverage is 47% for this particular file.
Have a customer who wants to pull metadata from SFDC and apply it to Box content.
When we call getChildren with offset and limitCount, in condition when the offset is close to the total items in a folder, it throws an assertion at LOC 593.
I have figured out the issue in a code and want to fix it.
Hello,
I am trying to connect Salesforce with box using JWT. Following this link(https://github.com/box/box-salesforce-sdk/blob/master/doc/platform.md). I am getting these errors:
Class.BoxPlatformApiConnection.constructJwtSignature: line 218, column 1
Class.BoxPlatformApiConnection.constructJwtAssertion: line 174, column 1
Class.BoxPlatformApiConnection.authenticate: line 134, column 1
Class.BoxPlatformApiConnection.getAppEnterpriseConnection: line 95, column 1
Am I missing some setup?
Thanks.
list<BoxItem.Info> children = folder.getChildren();
throws an exception
BoxJsonObject.BoxJsonObjectException: Json string passed to BoxJsonObject.parseJsonObjectArray was not valid json
The current checkContextForCallout() method looks like this:
private void checkContextForCallout() {
if (Limits.getLimitCallouts() < 1) {
throw new BoxApiRequestException('BoxApiRequest unable to make a callout due to no remaining callouts allowed (Limits.getLimitCallouts() == 0).');
}
}
However, getLimitCallouts() returns the per transaction callout limit -- so, 100 is always returned.
If the intent is to make sure that the number of callouts made so far hasn't hit the limit, then the method should probably be:
private void checkContextForCallout() {
if (Limits.getLimitCallouts() <= Limits.getCallouts()) {
throw new BoxApiRequestException('BoxApiRequest unable to make a callout due to no remaining callouts allowed.');
}
}
In the following code:
BoxFolder.Info info = folder.getFolderInfo();
BoxUploadEmail.Info emailInfo = info.uploadEmail;
emailInfo
will always be null, because the class isn't parsing the json response correctly for the upload email info. Per the docs, the correct json tag is folder_upload_email
; the code is checking for upload_email
. PR forthcoming.
When trying to deploy via Deploy to Salesforce Functionality, the deploy fails with multiple errors all pointing to BoxFile.cls
classes/BoxFile.cls(263,14):Missing ';' at 'responseBody'
There is a missing assignment at line 263. In
String responseBody BoxApiRequest.ensureBoxResourceResponseBody(response, 'BoxFile.getTrashedFile', new set<Integer>{200});
Should be
String responseBody = BoxApiRequest.ensureBoxResourceResponseBody(response, 'BoxFile.getTrashedFile', new set<Integer>{200});
If this issue is not already being addressed, I'll create a PR.
I am using the JWT auth and not able to connect with the app user after creating one through enterprise connection. ` BoxJwtEncryptionPreferences preferences = new BoxJwtEncryptionPreferences();
preferences.setPublicKeyId(publicKeyId);
preferences.setPrivateKey(privateKey);
BoxPlatformApiConnection pApi = BoxPlatformApiConnection.getAppEnterpriseConnection(userId, clientId, clientSecret, preferences);
BoxApiConnection api = new BoxApiConnection (pApi.getAccessToken()); //create api instance
BoxUser.createAppUser (api, 'appUser2');
`
This one successfully gives me the token and creates a user for the app.
After that one I am trying to getappuserconnection but getting error. What am I missing? My app is configured to work with app users.
BoxPlatformApiConnection pApi = BoxPlatformApiConnection.getAppUserConnection(userId, clientId, clientSecret, preferences);
When the SDK was originally written, the decision was made to use custom JSON parsing for a few reasons:
-Some fields required custom handling (datetime fields, for example)
-Consistency with the Box Java SDK
After real-world use, it turns out that these reasons are inadequate to justify a custom JSON parser. Simply defaulting to the built in JSON class methods is a much better option both in terms of performance and usability.
Ran into an issue where getting the current User failed with "Invalid long: 1.0e+15"; the stack trace and inspection of the raw response show that the raw JSON response includes:
"space_amount":1.0e+15
which BoxUser.Info is trying to parse as a long(); Apex's long.valueOf(x) method cannot parse scientific notation.
Looks like commit c4b5287 addressed that issue for a space_amount number of other fields back in March; I just installed the SDK today using the "Sandbox Package Link" in the readme, and didn't get that fix. Not sure how to tell how old the installed code is, but it isn't current.
Uploading a file uses the URL template BoxFolder.UPLOAD_FILE_URL. There is a typo in that string where "parentId" should be "parent_id". Currently, making an upload call returns a 400.
Adding support for permanently deleting a file from trash
Hi,
I am trying to Create Membership for a group but not able find any method in Box SDK.(https://box-content.readme.io/reference#add-a-member-to-a-group).
Your help can be appreciated.
We are using box-salesforce-sdk to allow our community users to download and upload box files. We use JWT authentication and will sometimes issues of an invalid/non-unique JTI. We have contacted Box Support who mentioned that they had seen rate limits being hit on our account. This is similar to a problem that occurred in the node.js version of the SDK. box/box-node-sdk#403
Error Message
{"error":"invalid_grant","error_description":"Please check the 'jti' claim. A unique 'jti' value is required."}
The enterprise example from platform.md does not compile when used in a new class.
Line 8 Errors
Same errors for line 9 with the privateKey variable respectively.
The URL string has the limit parameter as item 0 and stream_position as item 1.
private static final String GET_ENTERPRISE_EVENTS_URL = '/events?stream_type=admin_logs&limit={0}&stream_position={1}';
But when replacing the values in the getEnterpriseEvents method, streamPosition is first and numberOfEventsLimit is second.
String url =
this.api.baseUrl +
String.format(
GET_ENTERPRISE_EVENTS_URL,
new List<String>{
streamPosition,
String.valueOf(numberOfEventsLimit)
}
);
This helped me to cover the gaps left in code coverage for:
It is not beautiful but I was in a jam and if you found this issue, I suspect you are too.
`
@istest
private class ppg_BoxPackageTests {
private static String url = 'https://example.com';
private static String method = 'GET';
private static String accessToken = 'accesstoken';
private static String refreshToken = 'refreshtoken';
private static String clientId = 'clientid';
private static String clientSecret = 'clientsecret';
@IsTest
static void boxFolder() {
String mockResponseBody = '{"type":"collaboration","id":"791293","created_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"created_at":"2012-12-12T10:54:37-08:00","modified_at":"2012-12-12T11:30:43-08:00","expires_at":null,"status":"accepted","accessible_by":{"type":"user","id":"18203124","name":"sean","login":"[email protected]"},"role":"editor","acknowledged_at":"2012-12-12T11:30:43-08:00","item":{"type":"folder","id":"11446500","sequence_id":"0","etag":"0","name":"Shared Pictures"}}';
Test.setMock(HttpCalloutMock.class, new BoxTestMockCallout(mockResponseBody, 'Created', 201));
BoxApiConnection api = new BoxApiConnection('accesstoken');
BoxFolder folder = new BoxFolder(api, '11446500');
String folderInfoResponseBody = '{"type":"folder","id":"11446498","sequence_id":"1","etag":"1","name":"Pictures","created_at":"2012-12-12T10:53:43-08:00","modified_at":"2012-12-12T11:15:04-08:00","description":"Some pictures I took","size":629644,"path_collection":{"total_count":1,"entries":[{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"}]},"created_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"modified_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"owned_by":{"type":"user","id":"17738362","name":"sean rose","login":"[email protected]"},"shared_link":{"url":"https://www.box.com/s/vspke7y05sb214wjokpk","download_url":null,"vanity_url":null,"is_password_enabled":false,"unshared_at":null,"download_count":0,"preview_count":0,"access":"open","permissions":{"can_download":true,"can_preview":true}},"folder_upload_email":{"access":"open","email":"[email protected]"},"parent":{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"},"item_status":"active","item_collection":{"total_count":1,"entries":[{"type":"file","id":"5000948880","sequence_id":"3","etag":"3","sha1":"134b65991ed521fcfe4724b7d814ab8ded5185dc","name":"tigers.jpeg"}],"offset":0,"limit":100}}';
BoxFolder.Info folderInfo = new BoxFolder.Info(folderInfoResponseBody);
Test.startTest();
BoxCollaboration.Role collabRole = BoxCollaboration.Role.EDITOR;
BoxCollaboration.Info groupCollab = folder.collaborate(new BoxGroup(api, '791293'), collabRole);
BoxCollaboration.Info userCollab = folder.collaborate(new BoxUser(api, '829384'), collabRole);
folder.getCollaborations();
folder.deleteFolder(true);
folder.rename('bananaMangoSherbert');
folder.getFolderInfo();
folder.updateFolderInfo(folderInfo);
folder.uploadFile(Blob.valueOf('Who\'s a good blobby blob blob?'), 'SherbertBlob.pdf');
folder.uploadFile(new Attachment(Body = Blob.valueOf('Who\'s a good blobby blob blob?')), 'MangoBlob.pdf');
folder.uploadFile(new Document(Body = Blob.valueOf('Who\'s a good blobby blob blob?')), 'BananaBlob.pdf');
folder.getChildren();
folder.getChildren(2, 10);
Test.stopTest();
// No Asserts because we don't create this logic, just trying to cover it so we can deploy this unmanaged package to production.
}
@IsTest
static void apiRequest() {
list<BoxTestMockCallout.MockResponse> responses = new list<BoxTestMockCallout.MockResponse>();
BoxTestMockCallout.MockResponse redirectResponse = new BoxTestMockCallout.MockResponse('{"status":"redirect"}', 'REDIRECT', 301);
responses.add(redirectResponse);
BoxTestMockCallout.MockResponse successResponse = new BoxTestMockCallout.MockResponse('{"Status":"success"}', 'OK', 200);
responses.add(successResponse);
Test.setMock(HttpCalloutMock.class, new BoxTestMockCallout(responses));
Test.startTest();
BoxApiConnection api = new BoxApiConnection(clientId, clientSecret, accessToken, refreshToken);
api.lastRefresh = DateTime.now().getTime() - 5;
api.expires = api.lastRefresh + 60000;
BoxApiRequest request = new BoxApiRequest(api, url, method);
request.setBody('request body');
request.addJsonContentTypeHeader();
request.setMultipartFormBody(Blob.valueOf('request body'), 'requestfilename.pdf');
request.setTimeout(500);
HttpResponse finalResponse = request.send();
BoxApiRequest.ensureBoxResourceResponseCode(finalResponse, 'get', new Set<Integer> {400});
BoxApiRequest.getBoxResourceResponseBody(finalResponse, 'get');
try {
BoxApiRequest.ensureBoxResourceResponseCode(null, 'apiMethod', new Set<Integer> {400});
System.assert(false, 'Expected an exception to be thrown before we get to this point.');
} catch (Exception ex) {
System.assert(true, 'Expected a box exception because we passed in a null response into ensureBoxResourceResponseCode.');
}
try {
BoxApiRequest.getBoxResourceResponseBody(null, 'get');
System.assert(false, 'Expected an exception to be thrown before we get to this point.');
} catch (Exception ex) {
System.assert(true, 'Expected a box exception because we passed in a null response into getBoxResourceResponseBody.');
}
Test.stopTest();
System.assertEquals(200, finalResponse.getStatusCode());
}
@IsTest
static void enterprise() {
String mockResponseBody = '{"chunk_size": 3,"next_stream_position": "28893355","entries": [{"source": null,"created_by": {"type": "user","id": "181216415","name": "sean rose","login": "[email protected]"},"created_at": "2012-12-12T10:53:43-08:00","event_id": "28893270","event_type": "ADD_LOGIN_ACTIVITY_DEVICE","ip_address": "67.218.117.3","type": "event","session_id": null},{"source": null,"created_by": {"type": "user","id": "181216415","name": "sean rose","login": "[email protected]"},"created_at": "2012-12-12T10:53:43-08:00","event_id": "28893272","event_type": "LOGIN","ip_address": "67.218.117.3","type": "event","session_id": null},{"source": {"type": "folder","id": "387630341","sequence_id": "0","name": "A BNE"},"created_by": {"type": "user","id": "181216415","name": "sean rose","login": "[email protected]"},"created_at": "2012-12-12T10:53:43-08:00","event_id": "28893354","event_type": "UPLOAD","ip_address": "67.218.117.3","type": "event","session_id": null}]}';
Test.setMock(HttpCalloutMock.class, new BoxTestMockCallout(mockResponseBody, 'OK', 200));
BoxApiConnection api = new BoxApiConnection('accesstoken');
BoxEnterprise enterprise = new BoxEnterprise(api,'10543463');
BoxEnterprise.Info enterpriseInfo = new BoxEnterprise.Info();
enterpriseInfo.addValue('name', 'Tv Enterprise');
enterpriseInfo.addValue('name', new BoxEnterprise.Info());
enterpriseInfo = new BoxEnterprise.Info('{"name": "Tv Enterprise"}');
Test.startTest();
list<BoxEvent.Info> events = enterprise.getEnterpriseEvents();
System.assertNotEquals(null, enterprise.getObjectType(), 'Expected the object type to not be null.');
System.assertEquals(3, events.size());
events = enterprise.getEnterpriseEvents(10, 'streamPosition', 'eventType', 'createdAfter', 'createdBefore');
Test.stopTest();
}
@IsTest
static void emailAlias() {
BoxApiConnection api = new BoxApiConnection('accesstoken');
BoxEmailAlias boxEmailAlias = new BoxEmailAlias(api,'10543463');
BoxEmailAlias.Info emailAliasInfo = new BoxEmailAlias.Info();
emailAliasInfo = new BoxEmailAlias.Info('{"email": "[email protected]" }');
emailAliasInfo = new BoxEmailAlias.Info(emailAliasInfo);
emailAliasInfo.addValue('email', '[email protected]');
emailAliasInfo.addValue('email', emailAliasInfo);
boxEmailAlias.getObjectType();
boxEmailAlias.setInfo(emailAliasInfo);
Test.startTest();
emailAliasInfo.parseMember('is_confirmed', 'true');
emailAliasInfo.parseMember('email','[email protected]');
Test.stopTest();
System.assertEquals(true, emailAliasInfo.isConfirmed);
System.assertEquals('[email protected]', emailAliasInfo.email);
}
@IsTest
static void uploadEmail() {
BoxApiConnection api = new BoxApiConnection('accesstoken');
BoxUploadEmail uploadEmail = new BoxUploadEmail(api,'10543463');
BoxUploadEmail.Info uploadEmailInfo = new BoxUploadEmail.Info();
uploadEmailInfo = new BoxUploadEmail.Info('{"access": "open"}');
uploadEmailInfo.addValue('email', '[email protected]');
uploadEmailInfo.addValue('key', uploadEmailInfo);
Test.startTest();
uploadEmailInfo.parseMember('access', 'open');
uploadEmailInfo.parseMember('email', '[email protected]');
uploadEmail.getObjectType();
uploadEmail.setInfo(uploadEmailInfo);
Test.stopTest();
System.assertEquals(BoxUploadEmail.Access.OPEN, uploadEmailInfo.access);
System.assertEquals('[email protected]', uploadEmailInfo.email);
}
}
`
Hi,
In the Salesforce SDK, I am not able to find the Metadata and Search classes, although they are available in the java sdk. Can you please let me know how we can get doc meta-data and search for documents using the Salesforce SDK. Hoping for a quick response as its hampering our further development.
Ability to notify the client(End User) when a NEW file to view is available.
I.E: IF a new file has been uploaded to the box and is in a portal(UI) folder want to indicate to the client that a new document is available to view.
Note: We just want to indicate our end user that you have a new notification as you don't view this particular(New/Existing) file
Exp- In Attached Picture, there is Banking Form(A Box-Folder which has a file which havnt preview by this user)
We have deployed complete sdk and encountered compilation errors below. Can we have updated test classes please.
Compilation Complete
Compilation Errors found:
BoxApiRequestTests: line 123, column 27: Variable does not exist: HEADER_LOCATION_LOWER_CASE
BoxApiRequestTests: line 129, column 17: Method is not visible: System.HttpResponse BoxApiRequest.handleRedirect(System.HttpResponse)
BoxApiRequestTests: line 172, column 27: Variable does not exist: HEADER_LOCATION_CAPITALIZED
BoxApiRequestTests: line 178, column 17: Method is not visible: System.HttpResponse BoxApiRequest.handleRedirect(System.HttpResponse)
BoxFileTests: line 260, column 41: Method does not exist or incorrect signature: void getExpiringEmbedLink() from the type BoxFile
BoxFileTests: line 301, column 50: Method does not exist or incorrect signature: void getTrashedFile() from the type BoxFile
BoxTestMockCallout: line 55, column 35: Variable does not exist: HEADER_LOCATION_LOWER_CASE
BoxTestMockCallout: line 60, column 35: Variable does not exist: HEADER_LOCATION_CAPITALIZED
With the move to Lightning Experience, Attachments are being replaced by Files. We currently make it easy to upload attachments from Salesforce to Box. We should do the same for files.
Tried to push revision and submit pull request but received 403. The custom error messages in BoxApiRequest (lines 134, 136) provide no useful information. Messaging should utilize response.getBody() to provide useful debugging info. If you approve me, I can submit PR for your review.
You don't have an access to getObjectType() method from BoxItem.Info instance.
This code will not work: https://github.com/box/box-salesforce-sdk/blob/master/doc/folders.md#get-a-folders-items
Failures:
classes/BoxApiConnection.cls(69,37):Dependent class is invalid and needs recompilation:
Class.BoxApiRequest.getBoxResourceResponseBody: line 205, column 23
BoxResource: line 36, column 36: Dependent class is invalid and needs recompilation:
BoxFolder: line 341, column 12: Invalid type: BoxFile.Info
classes/BoxApiConnectionTests.cls(11,37):Dependent class is invalid and needs recompilation:
Class.BoxApiConnection.authenticate: line 69, column 37
This is super bad!
Winter '17 introduces JWT and JWS classes to handle JSON Web Token interactions. Once Winter '17 has been deployed to all orgs, that code should be rewritten to take advantage of these methods rather than being custom implementations.
Currently, the SDK only supports building a multipart/form-data body using the file content only. However, the Upload File Version operation supports additional body parameters for specifying a new 'name' as well as the 'content_modified_at' attribute. (https://developer.box.com/reference#upload-a-new-version-of-a-file)
(The "BoxBase64" class itself seems to be non-standard (looks like it's blending in some "quoted-printable" encoding?, etc.), and we've been unsuccessful at trying to modify this class to support the additional body parameters...)
The workaround is to upload the new file version then rename the file in a separate request.
Instead of passing in the private key as base64, you can sign by reference to a private key managed by the platform.
Check out this method:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_crypto.htm#apex_System_Crypto_signWithCertificate
In BoxUser, when parsing spaceUsed, spaceAmount, and maxUploadSize, the values may be returned in scientific notation. Simply calling long.valueOf(value) results in an exception.
The SDK doesn't currently support bookmarks (aka web links).
Could you add a badge with the code coverage?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.