Write code in Zapier Functions

With Zapier Functions, you have one main Python file that is run whenever your triggers have new output. You can also create multiple Python code files to separate and organize your functions. 

Beta

This product is in open beta. It’s available for use but still in active development and may change.

Working with the main.py file

The main.py file is added automatically when you create a new function. When your functions are deployed, this is the file that runs whenever your trigger events occur. You can reference trigger fields in it, import common Python packages, and reference other code files you create. You cannot delete this file.

Add actions to your code

You can add actions from any public Zapier app to your code. To insert a new action into your code:

  1. In any line of your code file, start typing zapier.action. to display a list of available apps in a dropdown menu. You can continue typing to find the one you want. To select the app, press the Enter or Tab key.
  2. Enter a period to see the dropdown menu of available actions.
  3. Select the action and press the Enter or Tab key. The account_id field will be added to the code.
  4. Move the cursor to the account_id field and press the CTRL + Space keys to display a list of existing connections.
  5. Start typing the connection's name to filter the list. You can also add a new connection.
  6. Once the connection is done, the code will populate the parameters for that action, and you can insert variables or references to trigger outputs.
Tip
  • You can use CTRL + Space with most parameters to see if Zapier has auto-complete options to help you set up your action.
  • You can change the CTRL + Space hotkey in the code editor settings.

Reference trigger outputs

While you edit a code file, you can reference the output from any of your trigger files. To reference a trigger output field:

  1. On the right sidebar, click the Selected trigger dropdown menu.
  2. Select the trigger output you want to reference in your code.
  3. In the code editor, start typing zapier.trigger_output. to display a dropdown menu with available fields.
  4. Move through the list and press the Enter or Tab key to select a field.
Tip

Use Tab to autocomplete the suggestions that appear while you type in the code editor.

Debug and inspect data

When you run your functions, you can add a print() statement to output and inspect the data that passed through the function, such as action responses. This allows you to test and debug your code. You can also view logs for all function runs and tests.

Create and use other code files

You can create separate code files to organize Python functions and then reference them in your main.py file.

To add a new code file:

  1. On the left sidebar, click the Explorer icon .
  2. In the CODE FILES section, click the plus sign +.
  3. In the text field that appears, enter the file name and press Enter.
  4. Import the new file into your main.py file so it can be run.

 

Example

You create a file called "new_file.py" with a function called hello. You can import the whole file by adding the following to your main.py file:

Import new_file

Then, call the hello function by typing:

new_file.hello()

Or, you can import only the hello function from your file by adding the following:

from new_file import hello

Then you can use the function anywhere on your code by typing:

hello()

Use Python packages

You can also use most common Python packages with Zapier Functions by referencing them on your file, using import <package_name>. You can change which version you use from the Packages menu.

 Learn how to import and change package versions.

Provide feedback and get help

Submit a feature request, provide feedback on existing features, or get help from the Zapier Functions team. You can also discuss Functions with other users on Zapier's Early Access Program Slack.

Was this article helpful?
1 out of 2 found this helpful