Set 'ExpirationsDays' on a Folder using Sharefile REST API

  • 1
  • Question
  • Updated 5 days ago
  • (Edited)
Hi,


We currently have a working solution (script) for creating ShareFile folders using the ShareFile API, and now need to set the property ‘ExpirationDays’ on new folders that we create. And here is where I struggle and would anyone's help/input.


 When I run below code, the folder will be created with a value of “-1” for ExpirationDays, despite me specifying “10” as a value. So I figured this is due a bug in the API code, so next solution I tried was to do a PATCH on the folder instead to change the value, but that only gives me ‘MethodNotAllowed’ error.

Is it not possible to specify ExpirationDays when creating a folder?
Is my synytax incorrect regarding the PATCH command?

Write-Host "Creating new Shared Folder.."
$newFolder = New-Object ShareFile.Api.Models.Folder
$newFolder.ExpirationDays = 10
$newFolder.Name = $clientNameSpecified
$newFolder.Description = "Folder for users related to $clientNameSpecified" $newFolder | Format-List *

$createdFolder = Send-SfRequest -Client $sfClient -Entity Items -Method POST -Navigation Folder -Body $newFolder

$createdFolder | Format-List * Write-Host "Done creating new Shared Folder!" #Despite above the folder will be created with a value of -1 on property ExpirationDays



 #Trying to change value using PATCH, but gives “MethodNotAllowed”..

Write-Host "Changing ExpirationDays.."
$createdFolderID = $($createdFolder.id)
$requestJSON = '[ { "ExpirationsDays":"10" }]' $requestJSON
$createdFolderPatched2 = Send-SfRequest -Client $sfClient -Entity Items -Method PATCH -Id $createdFolderID -Navigation Folder -BodyText $requestJSON
$createdFolderPatched2 | Format-List *


Images showing output of above:
https://imgur.com/a/uvVrYDi
Photo of rasmus.kindberg

rasmus.kindberg

  • 3 Posts
  • 1 Reply Like
  • https://imgur.com/a/uvVrYDi

Posted 4 months ago

  • 1
Photo of Pratik Somanagoudar

Pratik Somanagoudar, Software Engineer

  • 28 Posts
  • 4 Reply Likes
Hi Ramus,

I saw your request, and looking at the content you provided to the endpoint it seems like you are passing a List of Folder rathar than a folder in the JSON body for the endpoint. Request you to kindly check the input and let me know if you feel things are correct 
Also, I noticed that you are using .com domain instead of .eu (some calls on the account that we noticed) for this account that is supposed to be in EU. There would not be any significant differences but calling the .eu domain my give you better performance.

Thanks
Pratik
Photo of rasmus.kindberg

rasmus.kindberg

  • 3 Posts
  • 1 Reply Like
Thank you for your reply. Can you be a bit more specific regarding what line above is actually incorrect? From what I can tell there is no array/list object of Folders..?
Photo of Pratik Somanagoudar

Pratik Somanagoudar, Software Engineer

  • 28 Posts
  • 4 Reply Likes
PATCH Items(Id)/Folder will return Method Not Allowed. However PATCH Items(Id) with the expiration days should set the required value. 
Photo of rasmus.kindberg

rasmus.kindberg

  • 3 Posts
  • 1 Reply Like
Got it working now by using the 'URI' parameter to specify path. Thanks Pratik!

Working code:

$createdFolder = Send-SfRequest -Client $sfClient -Entity Items -Method POST -Navigation Folder -Body $newFolder
#$createdFolder | Format-List *
Write-Host "Done creating new Shared Folder!"


Write-Host "Changing ExpirationDays.." 
$createdFolderID = $($createdFolder.id) 
$requestJSON = '{"ExpirationDays":"180"}'
$folderUrl = "https://XXX.sf-api.eu/sf/v3/Items($createdFolderID)"
$createdFolderPatched2 = Send-SfRequest -Client $sfClient -Method PATCH -Uri $folderUrl -BodyText $requestJSON
#$createdFolderPatched2 | Select ExpirationDays
Photo of Pratik Somanagoudar

Pratik Somanagoudar, Software Engineer

  • 28 Posts
  • 4 Reply Likes
Great. Let us know if you need any help in future.