Automation Blog

How to Delay for 1–30 Seconds in a Zapier Code Step Using JavaScript or Python

When you need a short pause inside a Code step — between sequential API calls in a loop, after a write before a read, or to respect a rate limit — JavaScript's Promise-based setTimeout and Python's time.sleep both work reliably in Zapier Code steps.

ZapierCode StepsAPI

By Troy Tessalone · · 4 minutes

Automation Guide

A practical field guide from Automation Ace.

How to Delay for 1–30 Seconds in a Zapier Code Step Using JavaScript or Python

Zapier's Delay by Zapier action pauses between steps, but if you need a delay inside a Code step — between iterations of a loop, between two API calls made within the same step, or after a POST before a GET to the same service — you need the delay to happen within the code itself. JavaScript Code steps support await with a Promise wrapper around setTimeout. Python Code steps support time.sleep(). Both work exactly as expected in Zapier's execution environment.

Why You Might Need an In-Step Delay

The most common reasons to add a programmatic pause inside a Code step rather than using a separate Delay step:

  • Rate limiting inside a loop: A Code step making 10 sequential API calls needs 1 second between each call to stay under the API's rate limit. A loop with an in-step delay handles this in a single Code step — no separate Delay step, no extra task per iteration.
  • Write-then-read sequencing: After a POST to create a record, a short pause before the GET that reads the record gives the API time to commit the write before the read fires.
  • Webhook acknowledgment timing: Some services that receive a webhook need a brief pause before responding to a follow-up API call to the same service.
  • Pagination with throttling: Fetching all pages from a paginated API that throttles at N requests per second — sleep between page fetches.

JavaScript: Delay with setTimeout and a Promise

Zapier's JavaScript Code step environment supports async/await and setTimeout. Wrap setTimeout in a Promise to make it awaitable:

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

// Example: sequential API calls with 2-second pause between each
const ids = inputData.ids.split(',').map(s => s.trim());
const results = [];

for (const id of ids) {
  const response = await fetch(`https://api.example.com/records/${encodeURIComponent(id)}`, {
    headers: { 'Authorization': 'Bearer ' + inputData.api_token }
  });
  const data = await response.json();
  results.push({ id, name: data.name || '', status: data.status || '' });

  await sleep(2000); // wait 2 seconds before next request
}

output = {
  count: String(results.length),
  results: JSON.stringify(results)
};

The sleep helper accepts milliseconds — sleep(1000) is 1 second, sleep(500) is half a second, sleep(30000) is 30 seconds. Keep the total delay within the Code step's execution timeout; Zapier JavaScript Code steps have a 30-second execution limit by default (some plans extend this).

JavaScript: Delay Between a Write and a Read

A common pattern: create a record via POST, wait for it to be committed, then fetch it via GET:

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

// Create the record
const createResponse = await fetch('https://api.example.com/contacts', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer ' + inputData.api_token,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ email: inputData.email, name: inputData.name })
});
const created = await createResponse.json();
const newId = created.id;

// Wait 3 seconds for the API to commit the write
await sleep(3000);

// Fetch the newly created record
const getResponse = await fetch(`https://api.example.com/contacts/${newId}`, {
  headers: { 'Authorization': 'Bearer ' + inputData.api_token }
});
const contact = await getResponse.json();

output = {
  id: String(newId),
  email: contact.email || '',
  status: contact.status || '',
  created_at: contact.created_at || ''
};

Python: Delay with time.sleep()

Python's time module is available in Zapier Python Code steps. time.sleep() takes seconds as a float — use decimals for sub-second precision:

import requests
import time

url = 'https://api.example.com/contacts'
headers = {
    'Authorization': f"Bearer {input_data['api_token']}",
    'Accept': 'application/json'
}

ids = [s.strip() for s in input_data['ids'].split(',')]
results = []

for record_id in ids:
    response = requests.get(f"{url}/{record_id}", headers=headers)
    response.raise_for_status()
    data = response.json()
    results.append({'id': record_id, 'name': data.get('name', ''), 'status': data.get('status', '')})
    time.sleep(1.5)  # 1.5 seconds between requests

return {
    'count': str(len(results)),
    'results': str(results)
}

For sub-second delays use time.sleep(0.5) (500ms). For longer pauses use whole numbers: time.sleep(10) is 10 seconds. Python Code steps also run within a timeout limit — account for accumulated sleep time across all loop iterations when processing large lists.

Delay Duration Guidance

Common delay values by use case:

  • 500ms–1s: Light rate limiting between sequential calls to a generous API (e.g., 60 requests/minute limit with small list sizes)
  • 1–2s: Standard inter-request pacing for most REST APIs with moderate rate limits
  • 3–5s: Write-then-read sequencing where the upstream API has observable commit latency
  • 10–30s: Aggressive rate-limited APIs, or when waiting for a triggered async process to complete before checking its status

Check the API's documentation for its stated rate limit and calculate: if the API allows 30 requests per minute, you need at least 2 seconds between requests to stay within limits safely.

In-Step Delay vs. Delay by Zapier Action

Use a Delay by Zapier step when the pause is between Zap steps and the Code step itself doesn't need to do anything during the wait. Use an in-step delay when the pause is part of multi-operation logic happening within the Code step itself — particularly loops. An in-step delay doesn't consume extra Zapier tasks, while each Delay step counts as one task per Zap run. For sequential looping patterns, see sequential looping in Zapier steps.

The sleep pattern — a Promise wrapper around setTimeout in JavaScript, or time.sleep() in Python — is one of the most useful tools for Code steps that make multiple API calls. Rate limiting, write-then-read timing, and pagination throttling all become trivial once you have a reliable in-step delay.

For more on sequential API calls inside a Code step, see HTTP GET requests in a Zapier Code step and HTTP POST requests in a Zapier Code step. For available JavaScript tools in Code steps, see JavaScript libraries in Zapier Code steps. For help designing a rate-limited API integration, talk to Automation Ace.

ZapierCode StepsAPI

Disclaimer: This article may include links to apps, products, or services. Some links may be affiliate links, which means Automation Ace may earn a commission at no extra cost to you.

Build Better Systems

Ready to automate with confidence?

Share your tools, process, and goals. Automation Ace can design the workflow, integration, AI assist, or code bridge that fits your business.

Start a Project →