How to add a folder template when creating a folder using Powershell?

  • 1
  • Question
  • Updated 6 months ago
  • (Edited)
I can create a folder through Powershell reliably, but I cannot figure out how to make a new folder that follows a pre-defined Sharefile template. I have read the FolderTemplate API and still cannot figure it out. Here is my current code for creating my folder:
$folderInfo ='{
"Name":"'+$ExamName+'", 
"Description":"Auto-Generated Folder",
"templateId":"Template.Id" #<---- several variations with no effect
}'
$folder = Send-SfRequest -Client $mylogin -Entity Items -Method POST -Id $Folder.Id -Navigation Folder -BodyText $folderInfo
Photo of Erik

Erik

  • 4 Posts
  • 1 Reply Like

Posted 7 months ago

  • 1
Photo of Erik

Erik

  • 4 Posts
  • 1 Reply Like
Any insight on this? I am able to batch update using the JSON through the API page which is not really what I am looking for (because it goes through the entire parent folder very slowly to update only one folder to the desired template) but could serve as a duct-taped solution if it's implemented through powershell. I have not successfully done an invoke-webrequest with JSON through powershell however.
Photo of Scott

Scott, Employee

  • 8 Posts
  • 1 Reply Like
Hi Erik,

Please try using "AssociatedFolderTemplateID":"Template.Id" in the body.
(Edited)
Photo of Erik

Erik

  • 4 Posts
  • 1 Reply Like
Thank you Scott, that fixed the issue! Not sure why I could not find this in the documentation. I just spent a bulk of a day setting up Postman and Newman to run the JSON through Powershell/CMD as a wonky workaround that took ~3 seconds per folder (Not recommended unless all the subfolders of your parent folder need to be the same template). Here's my full code:

$folderInfo ='{
"Name":"'+$ExamName+'", 
"Description":"Auto-Generated Folder",
"AssociatedFolderTemplateID":"xxx-xxx-xxx"
}'
$folder = Send-SfRequest -Client $mylogin -Entity Items -Method POST -Id $Folderid -Navigation Folder -BodyText $folderInfo
(Edited)