Skip to main content
Question

Search through folder structure - Zapier CLI


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!

Did this topic help you find an answer to your question?
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

ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • August 4, 2021

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
}

 


  • Author
  • Beginner
  • 1 reply
  • August 12, 2021

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…