Question

Search through folder structure - Zapier CLI

  • 4 August 2021
  • 2 replies
  • 185 views

Userlevel 1

Hello guys,

I´m developing a Zapier App and its required to select a parent-folder to create something inside it. Im using the Zapier CLI and a wanted to ask how to generate a field with a folder-structure-view like shown in the image (example from the Google Drive Zapier App):

 

Thank you for your help in advance!


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 7
Badge +12

Hi @MaltesBytes - The folder structure view seems to be undocumented but I was able to use it before to create a custom Dropbox integration to support team accounts.

Here’s a code snippet showing how I did it. Make sure that the trigger’s key is directory and the folder input field’s key is also directory.

import path from "path";

const perform = async (z, bundle) => {
// Note: Dropdown input field key must be "directory"
const { directory } = bundle.inputData;

// This is just an example array of folders. In a real scenario, this would be fetched from an API
const folders = [
{
id: 1,
path: "/",
},
{
id: 2,
path: "/folder1",
},
{
id: 3,
path: "/folder1/folder2",
},
];

// Insert a link to parent folder
let parent = "/"; // Default parent folder: /
if (directory) {
const dirname = path.dirname(directory);
if (dirname !== ".") {
parent = dirname;
}
}
folders.unshift({
id: -1,
path: parent,
});

return folders;
};

export default {
key: "directory", // Must be "directory"
noun: "Folder",
display: {
label: "List folders",
description: "List all folders",
hidden: true,
},
operation: {
inputFields: [],
perform,
sample: {
id: 1,
path: "/",
},
},
};

 

The input field that uses this trigger to populate the dropdown should be defined like this:

{
"key": "directory",
"label": "Folder",
"dynamic": "directory.path.path",
"default": "/",
"required": true
}

 

Userlevel 1

Hello ikbelkirasan,

thank you for your advice to set the trigger’s key to “directory” and the folder input field’s key also to “directory”. Through that, I was able to display the desired directory-field-format (like in the picture of the original question). However, even after using your code, with the folders array as a replacement for an API, it still wasn’t working. No matter what I’m pressing, It's still showing me all the folders on the top level, and I can't scope the view only in the interior of one specific parent…