A practical field guide from Automation Ace.
How to Make an HTTP GET Request in a Zapier Code Step with Query String Parameters
HTTP GET requests are how you fetch data from an API — looking up a contact by email, retrieving a record by ID, searching for items matching a query. While Webhooks by Zapier handles simple GET requests without code, a Code step gives you the ability to build query parameters dynamically from Zap data, handle paginated responses, parse nested JSON structures, and apply conditional logic to what you fetch. This guide covers the patterns for making GET requests with query string parameters in both JavaScript and Python Zapier Code steps.
Building Query String Parameters Safely
Query string parameters must be URL-encoded — special characters in parameter values (spaces, &, =, etc.) must be escaped or the request will fail or misparse. Both JavaScript and Python have built-in tools for this.
JavaScript: GET with Query Parameters Using URLSearchParams
URLSearchParams is available as a global in Zapier's JavaScript Code step environment and handles URL encoding automatically:
const params = new URLSearchParams({
email: inputData.email,
limit: '10',
status: 'active'
});
const url = `https://api.example.com/contacts?${params.toString()}`;
const response = await fetch(url, {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + inputData.api_token,
'Accept': 'application/json'
}
});
if (!response.ok) {
const errorBody = await response.text();
throw new Error(`GET failed: ${response.status} ${errorBody}`);
}
const data = await response.json();
output = {
count: String(data.total || data.results?.length || 0),
first_result: JSON.stringify(data.results?.[0] || data),
raw_response: JSON.stringify(data)
};
URLSearchParams encodes each value correctly — if inputData.email contains an @ or + character, it is percent-encoded automatically. Always use URLSearchParams rather than manually concatenating parameter values into the URL string.
JavaScript: GET with a Dynamic Path Parameter and Query String
Many REST APIs combine a path parameter (a record ID in the URL path) with optional query string parameters:
const recordId = encodeURIComponent(inputData.record_id);
const params = new URLSearchParams({
fields: 'name,email,status,created_at',
expand: 'organization'
});
const url = `https://api.example.com/records/${recordId}?${params.toString()}`;
const response = await fetch(url, {
headers: {
'Authorization': `Bearer ${inputData.api_token}`,
'X-Api-Version': '2025-01'
}
});
if (!response.ok) throw new Error(`Error ${response.status}: ${await response.text()}`);
const record = await response.json();
output = {
name: record.name || '',
email: record.email || '',
status: record.status || '',
organization: record.organization?.name || '',
created_at: record.created_at || ''
};
Use encodeURIComponent() on path parameters (IDs that appear in the URL path itself) rather than URLSearchParams — the latter is designed for query string key-value pairs.
JavaScript: GET with API Key in Header vs. Query String
Some APIs pass the API key as a query parameter rather than a header:
// API key in query string (some APIs require this pattern)
const params = new URLSearchParams({
api_key: inputData.api_key,
q: inputData.search_term,
limit: '20'
});
const response = await fetch(`https://api.example.com/search?${params.toString()}`);
const data = await response.json();
output = { results: JSON.stringify(data.results || []) };
API keys in query strings are visible in server logs and browser history. When possible, prefer API keys in headers — but use whichever method the API documentation specifies.
JavaScript: Handling Paginated GET Responses
When an API returns paginated results and you need all pages, loop through pages in the Code step:
const allResults = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const params = new URLSearchParams({
page: String(page),
per_page: '100'
});
const response = await fetch(`https://api.example.com/items?${params}`, {
headers: { 'Authorization': 'Bearer ' + inputData.api_token }
});
const data = await response.json();
allResults.push(...(data.items || []));
hasMore = data.has_next_page === true;
page++;
if (page > 10) break; // safety limit
}
output = {
total: String(allResults.length),
results: JSON.stringify(allResults)
};
The safety limit (if (page > 10) break) prevents infinite loops if the API's pagination sentinel is unexpected. Adjust the limit based on expected data volume and Code step timeout constraints.
Python: GET with Query Parameters
The requests library in Python Code steps accepts query parameters as a dictionary via the params argument — it handles URL encoding automatically:
import requests
url = 'https://api.example.com/contacts'
headers = {
'Authorization': f"Bearer {input_data['api_token']}",
'Accept': 'application/json'
}
params = {
'email': input_data['email'],
'status': 'active',
'limit': '10'
}
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
data = response.json()
contacts = data.get('contacts', [])
return {
'count': str(len(contacts)),
'first_contact_name': contacts[0].get('name', '') if contacts else '',
'first_contact_email': contacts[0].get('email', '') if contacts else '',
'raw': str(data)
}
Parsing and Extracting Nested JSON
API responses often have nested structures. Use Python's .get() with defaults or JavaScript's optional chaining (?.) to safely extract nested values without errors when a field is missing:
// JavaScript: safe nested access
const city = data.address?.city || '';
const planName = data.subscription?.plan?.name || 'unknown';
const firstTag = data.tags?.[0]?.label || '';
Map the specific fields you need as named Code step output fields — downstream Zap steps can only use fields that are explicitly part of the output object.
When to Use Code Step GET vs. Webhooks by Zapier GET
Use Webhooks by Zapier GET for simple lookups where the URL is straightforward and the response fields map directly to what you need. Use a Code step GET when query parameters need to be built from multiple Zap fields, the response is nested and requires extraction, pagination is needed, or multiple GET calls must be made sequentially. For a comparison of both tools, see how to use APIs in Zapier steps.
The key to reliable GET requests in a Code step is always usingURLSearchParams(JavaScript) or theparamsdict (Pythonrequests) rather than manually concatenating values into the URL string. Unencoded special characters in query parameters are one of the most common causes of silent failures — the request goes through, but the server does not find what you were looking for because the parameter value was malformed.
For the POST request equivalent with JSON body and authentication, see HTTP POST requests in a Zapier Code step. For more on available Code step tools, see JavaScript libraries in Zapier Code steps and Python libraries in Zapier Code steps. For help with an API integration workflow, talk to Automation Ace.
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.