Collaboration Invites Create An Account
AnsweredI have a java program that runs every morning from my CRM. It walks a folder tree and updates the security for the folders based on the users role in my CRM. It's a fluid environment so I am changing users from editors, to owners or the other way around..... I am trying to find a way to update an existing collaboration object instead of deleting it an recreating it as this sends an email to the user. I can't seem to figure out how to update an existing collaboration. Here is my code below...
// Loop through the property's sub-folders for (final BoxFolder propertySubfolder : boxService.getSubFolders( propertyFolder )) { out.format( " %s%n", propertySubfolder.getInfo().getName() ); // Capture a list of all existing collaborators for later... List listOfCollaborators = new ArrayList(); for( final BoxCollaboration.Info collaboration : propertySubfolder.getCollaborations() ) { // Loop through existing collaborators and remove any groups so we can add them later with the appropriate access if( collaboration.getAccessibleBy() != null ) { String collabName = collaboration.getAccessibleBy().getName(); if( StringUtils.containsIgnoreCase( listOfGroupEditors.toString(), collabName ) ) { out.println( " Removing: " + collabName ); collaboration.getResource().delete(); } else { // Add all collaborators in this subfolder to a list for checking if we need to add collaborators later listOfCollaborators.add( collaboration ); } } } int index; BoxCollaboration.Info aCollaboration; // Add the regional directory as an editor if( regionalDirector != null ) {
// Do we have the collaborator object in the list? index = findCollaborator( regionalDirector, listOfCollaborators ); if( index == -1 ) { out.println( " Adding regional director: " + regionalDirector.getInfo().getName() ); propertySubfolder.collaborate( regionalDirector, BoxCollaboration.Role.CO_OWNER ); } else {
// Found it so update it aCollaboration = listOfCollaborators.get( index ); aCollaboration.setRole( BoxCollaboration.Role.CO_OWNER ); // how do I update the collaboration object????? } }
-
I think if you pass "notify=false" as a query parameter to the API call it should silent all notifications.
https://github.com/box/box-java-sdk/blob/master/src/main/java/com/box/sdk/BoxCollaboration.java#L59
-
, I went through the java sdk and saw that parameter in the low level code but sadly the methods that I am using exclude those parameters as they pass null values to the underlying methods ugh.
public BoxCollaboration.Info collaborate(BoxCollaborator collaborator, BoxCollaboration.Role role) { JsonObject accessibleByField = new JsonObject(); accessibleByField.add("id", collaborator.getID()); if (collaborator instanceof BoxUser) { accessibleByField.add("type", "user"); } else if (collaborator instanceof BoxGroup) { accessibleByField.add("type", "group"); } else { throw new IllegalArgumentException("The given collaborator is of an unknown type."); } return this.collaborate(accessibleByField, role, null, null);
-
Hey , I think the best thing might be to address your original question around updating a collab. From looking at our docs, we have this laid out:
https://github.com/box/box-java-sdk/blob/master/doc/collaborations.md#edit-a-collaboration
A collaboration can be edited by creating a new
BoxCollaboration.Info
object or updating an existing one, and then passing it toupdateInfo(BoxCollaboration.Info fieldsToUpdate)
BoxCollaboration collaboration = new BoxCollaboration(api, "id"); BoxCollaboration.Info info = collaboration.new Info(); info.setStatus(BoxCollaboration.Status.ACCEPTED); collaboration.updateInfo(info);
It looks like this might be what you need re:updating a collab?
Otherwise, the behavior around emails and new collaborations are expected. Emails will always get sent out for those.
From our docs at:
https://developer.box.com/reference#suppressing-notifications
User creation, comment, collaboration creation, change user's login, and task assignment notifications cannot be suppressed using this header.
Let us know if you're able to make that collaboration update method work, or if you try something but it doesn't quite get you all the way there.
-
I agree and would much rather update an existing collaboration. The
documentation is not clear to me anyhow, how to create a new collaboration.
Specifically, the parameter "id". Surely I can't use that string "id". So
how do I come up with the id for that call? In my code, I have the
existing collaboration.info object . Is there anyway to use that?
BoxCollaboration collaboration = new BoxCollaboration(api, "id");
BoxCollaboration.Info info = collaboration.new Info();
info.setStatus(BoxCollaboration.Status.ACCEPTED);
collaboration.updateInfo(info);
Here is my code...
// Loop through the property's sub-folders
for (final BoxFolder propertySubfolder : boxService.getSubFolders
( propertyFolder ))
{
// Capture a list of all existing collaborators for later...
List listOfCollaborators = new ArrayList();
for( final BoxCollaboration.Info collaboration :
propertySubfolder.getCollaborations() )
{
// Loop through existing collaborators and remove any groups
so we can add them later with the appropriate access
if( collaboration.getAccessibleBy() != null )
{
String collabName = collaboration.getAccessibleBy
().getName();
if( StringUtils.containsIgnoreCase
( listOfGroupEditors.toString(), collabName ) )
{
out.println( " Removing: " + collabName );
collaboration.getResource().delete();
}
else
{
// Add all collaborators in this subfolder to a
list for checking if we need to add collaborators later
listOfCollaborators.add( collabName );
}
}
}
// Add the regional directory as an editor
if( regionalDirector != null )
{
index = findCollaborator( regionalDirector,
listOfCollaborators );
if( index == -1 )
{
out.println( " Adding regional director: " +
regionalDirector.getInfo().getName() );
propertySubfolder.collaborate( regionalDirector,
BoxCollaboration.Role.EDITOR, false, null );
}
else
{
aCollaboration = listOfCollaborators.get( index );
aCollaboration.setRole( BoxCollaboration.Role.EDITOR );
// now what?
}
}
} -
Good morning !
To answer the question on creating a new collab, the "id" would be the ID of either the file or folder:
https://github.com/box/box-java-sdk/blob/master/doc/collaborations.md#add-a-collaboration
Those file/folder IDs should be returned when your code is "walking" through the folder structure, presumably here:
// Loop through the property's sub-folders for (final BoxFolder propertySubfolder : boxService.getSubFolders( propertyFolder )) { out.format( " %s%n", propertySubfolder.getInfo().getName() );
And you'd probably want .getID()
http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxResource.Info.html#getID--
However, since it sounds like you are trying to get a file/folder ID based on a collaboration, you can find information about the item in the "item" field on the collaboration:
An example JSON response from the API on the GET Collaboration Info call can be found at:
https://developer.box.com/reference#get-collabs
{ "type": "collaboration", "id": "791293", "created_by": { "type": "user", "id": "17738362", "name": "sean rose", "login": "sean@box.com" }, "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": "sean+test@box.com" }, "role": "editor", "acknowledged_at": "2012-12-12T11:30:43-08:00", "item": { "type": "folder", "id": "11446500", "sequence_id": "0", "etag": "0", "name": "Shared Pictures" }
Note the "item" field at the bottom. You would request that "ITEM" field and pull the "id" from there.
-
Thank you so much for the help.
Just to provide the solution in case anyone else is looking for it as I was, here is my code....
int index; BoxCollaboration aCollaboration; BoxCollaboration.Info collaborationInfo; // Add the regional directory as an editor if( regionalDirector != null ) { // Find the collaboration.info object if we have it... index = findCollaborator( regionalDirector, listOfCollaborators ); // If not found if( index == -1 ) { // Add the collaborator to the subFolder out.println( " Adding regional director: " + regionalDirector.getInfo().getName() ); propertySubfolder.collaborate( regionalDirector, BoxCollaboration.Role.EDITOR, false, null ); } else { // Fetch the collaboration.info object stored above collaborationInfo = listOfCollaborators.get( index ); // Create a new collaboration object using the collaboration.info id aCollaboration = boxService.createBoxCollaboration( collaborationInfo.getID() ); // Update the role as needed collaborationInfo.setRole( BoxCollaboration.Role.EDITOR );
// This doesn't work as it must be pending to accept it.
// collaborationInfo.setStatus( Status.ACCEPTED );
// Update the collaboration.
aCollaboration.updateInfo( collaborationInfo ); } } -
If it always sends emails for new collaborations then why have the boolean parameter notify that says "Determines if users should receive email notification for the action performed." I am trying to using node api and notify parameter is not being respected
Here's the code:createCollaboration({ item, accessibleBy, role }, options = {}) { return this.request({ ...options, body: { item, accessible_by: accessibleBy, role, notify: false, }, method: 'POST', path: '/2.0/collaborations/', }); }
-
Also side note, all of the box reference links formatted like https://developer.box.com/reference#suppressing-notifications are broken they all forward to the same generic page
-
wrote:If it always sends emails for new collaborations then why have the boolean parameter notify that says "Determines if users should receive email notification for the action performed." I am trying to using node api and notify parameter is not being respected
Here's the code:createCollaboration({ item, accessibleBy, role }, options = {}) { return this.request({ ...options, body: { item, accessible_by: accessibleBy, role, notify: false, }, method: 'POST', path: '/2.0/collaborations/', }); }
SOLVED
I was being a dumby, sticking it into the body rather than the query, ignore me
Please sign in to leave a comment.
Comments
12 comments