Notify Users after Adding AccessControl to a Folder (powershell)

  • 1
  • Question
  • Updated 3 months ago
I've managed to cobble together how to add and remove access to a shared folder using powershell (with recursion).  It works great.

Now I am trying to notify the users that they have access in the same way as on the website where it shows ("Notify added users").

I can see in the API that there is this call, but I can't quite figure out how to get it to work.
Notify users that they have access to the parent folder


<a target="_blank" rel="nofollow" href="http://api.sharefile.com/rest/login.aspx?displayMessage=1&referrer=/rest/docs/resource.aspx?name=AccessControls" title="Link http//apisharefilecom/rest/loginaspxdisplayMessage1referrer/rest/docs/resourceaspxnameAccessControls">POST</a> https://account.sf-api.com/sf/v3/Items(id)/AccessControls/NotifyUsers<br><code>
{ 
&nbsp;&nbsp;&nbsp;&nbsp;UserIds: ["id1", "id2"],
&nbsp;&nbsp;&nbsp;&nbsp;CustomMessage: "Message content goes here"
}

All users should have access to the parent folder
folderId - String - ID of Parent item
notifyUsersParams - NotifyUsersParams - Parameter container

For coding purposes, I have 
$itemID = the ID of the folder with permissions granted
$userID = the ID of the user (single, not multiple as above)
$sfC = the share file client

Send-SfRequest -Client $sfC -Method POST -Entity items -Id $itemID -Navigation "AccessControls/NotifyUsers" -BodyText $reqJSON

I'm not sure how to create the variable for -BodyText (i.e. what's the correct syntax to provide the $userID and a brief CustomMessage)

I get this error:
Send-SfRequest : InternalServerError: System error
At line:1 char:1
+ Send-SfRequest -Client $sfC -Method POST -Entity items -Id $itemID -Navigation " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (items:String) [Send-SfRequest], Exception
    + FullyQualifiedErrorId : InternalServerError,ShareFile.Api.Powershell.SendSfRequest

Thanks,

Zack
Photo of Zack Eleveld

Zack Eleveld

  • 16 Posts
  • 4 Reply Likes

Posted 3 months ago

  • 1
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 50 Posts
  • 6 Reply Likes
Hi Zack,

In powershell, you should be able to do something similar to this:
$req = New-Object ShareFile.Api.Models.NotifyUsersParams
$req.UserIds = New-Object System.Collections.Generic.List[string]
$req.UserIds.Add("user1")
$req.CustomMessage = "Hello"

Then you can pass the object to the Send-SfRequest via the -Body parameter
(Edited)
Photo of Zack Eleveld

Zack Eleveld

  • 16 Posts
  • 4 Reply Likes
I don't have the Model (sharefile.api.models.notifyusersparams).  I get the error:
new-object : Cannot find type [sharefile.api.models.notifyUsersParams]: verify that the assembly containing this type is loaded.
I tried to create a custom object instead:
$req = @{}
$req.UserIds = New-Object 'System.Collections.Generic.List[string]'
$req.UserIds.Add($attyID.Id)
$req.CustomMessage = "Hello Testing"
$req
Name                           Value                                                                                                                 
----                           -----                                                                                                                 
CustomMessage                  Hello Testing                                                                                                         
UserIds                        {26b636cc-9f6f-4977-a429-8339631db251}
Then I tried these commands with this result.

PS C:\Users\sync> Send-SfRequest -Client $sfC -Method POST -Entity items($itemID) -Navigation "AccessControls/NotifyUsers" -Body $req
Send-SfRequest : Cannot bind parameter 'Body'. Cannot create object of type "ShareFile.Api.Models.ODataObject". The CustomMessage property was not 
found for the ShareFile.Api.Models.ODataObject object. The available property is: [MetadataUrl <System.String>] , [__type <System.String>] , [Id 
<System.String>] , [url <System.Uri>]
At line:1 char:112
+ ... fyUsers" -Body $req
+                    ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Send-SfRequest], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,ShareFile.Api.Powershell.SendSfRequest
 
PS C:\Users\sync> Send-SfRequest -Client $sfC -Method POST -Entity items($itemID) -Navigation "AccessControls/NotifyUsers" -BodyText $req
Send-SfRequest : InternalServerError: System error
At line:1 char:1
+ Send-SfRequest -Client $sfC -Method POST -Entity items($itemID) -Navigation "Acc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (items:String) [Send-SfRequest], Exception
    + FullyQualifiedErrorId : InternalServerError,ShareFile.Api.Powershell.SendSfRequest


Any Suggestions?

Zack
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 50 Posts
  • 6 Reply Likes
What version of the snap-in are you using? (you can use "Get-PSSnapin ShareFile" to check)

The latest is 1.92
Name        : ShareFile
PSVersion   : 1.0
Description : PowerShell Snap-In for ShareFile API. Version 1.92
Photo of Zack Eleveld

Zack Eleveld

  • 16 Posts
  • 4 Reply Likes
I'm only on 1.5.  Is upgrading easy?

Name        : ShareFile
PSVersion   : 1.0
Description : PowerShell Snap-In for ShareFile API. Version 1.5

Zack
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 50 Posts
  • 6 Reply Likes
It should be fairly straightforward. You can find the msi for the latest version here: https://github.com/citrix/ShareFile-PowerShell/releases
Photo of Zack Eleveld

Zack Eleveld

  • 16 Posts
  • 4 Reply Likes
Thanks Luke.  With the snapin updated, everything worked correctly.

Zack