How to append action fields to request URL as query parameters in Zapier scripting

I need help with modifying the URL in a Zapier script by adding action field data as query string parameters. I’m working with this bundle structure:

{
  "auth_fields": {
    "domain": "xyz", 
    "token": "5678"
  }, 
  "request": {
    "files": {}, 
    "url": "https://xyz.api.service.com/v2/task?&method=create", 
    "headers": {
      "Content-Type": "application/json; charset=utf-8", 
      "Accept": "application/json"
    }, 
    "params": {
      "token": "5678"
    }, 
    "data": "{\"priority\": \"HIGH\", \"title\": \"Sample Task\"}", 
    "method": "POST"
  }, 
  "action_fields": {
    "priority": "HIGH", 
    "title": "Sample Task"
  }
}

I tried this approach based on examples I found:

var ZapierApp = {
    task_before_request: function(bundle) {
        console.log(bundle.request.action_fields["priority"]);
        bundle.request.url = "https://xyz.api.service.com/v2/task?method=create";
        bundle.request.params = $.param(bundle.request.action_fields);
        console.log(bundle.request.params);
        return bundle.request;
    }
};

But I get this error: TypeError: Cannot read property 'jquery' of undefined. I want the final URL to be formatted like: https://xyz.api.service.com/v2/task?method=create&title=Sample%20Task&priority=HIGH&token=5678. What’s the correct way to convert action fields into query parameters without using jQuery?

zapier’s scripting environment doesn’t include jquery, so $.param() throws that error. use urlsearchparams instead - way cleaner than building strings manually:

var params = new urlsearchparams(bundle.action_fields);
params.append('token', bundle.request.params.token);
bundle.request.url = "https://xyz.api.service.com/v2/task?method=create&" + params.toString();

handles encoding automatically and no loops needed.

The problem is $.param() doesn’t exist in Zapier’s environment - jQuery isn’t loaded. You’ll need to build the query string manually from your action fields. Here’s what worked for me:

var ZapierApp = {
    task_before_request: function(bundle) {
        var baseUrl = "https://xyz.api.service.com/v2/task?method=create";
        var queryParams = [];
        
        // Add action fields as query parameters
        for (var key in bundle.action_fields) {
            if (bundle.action_fields.hasOwnProperty(key)) {
                queryParams.push(encodeURIComponent(key) + "=" + encodeURIComponent(bundle.action_fields[key]));
            }
        }
        
        // Add existing params like token
        for (var param in bundle.request.params) {
            if (bundle.request.params.hasOwnProperty(param)) {
                queryParams.push(encodeURIComponent(param) + "=" + encodeURIComponent(bundle.request.params[param]));
            }
        }
        
        bundle.request.url = baseUrl + "&" + queryParams.join("&");
        return bundle.request;
    }
};

This builds the query string manually and encodes everything properly - should get you the URL format you need.

You’re accessing bundle.request.action_fields but action_fields sits at the top level of the bundle object, not under request. Use bundle.action_fields instead. Hit this exact same problem last month on a similar integration. Here’s how your code should look:

var ZapierApp = {
    task_before_request: function(bundle) {
        var url = "https://xyz.api.service.com/v2/task?method=create";
        
        // Build query string from action_fields
        var params = [];
        Object.keys(bundle.action_fields).forEach(function(key) {
            params.push(key + "=" + encodeURIComponent(bundle.action_fields[key]));
        });
        
        // Add token from existing params
        if (bundle.request.params.token) {
            params.push("token=" + bundle.request.params.token);
        }
        
        bundle.request.url = url + "&" + params.join("&");
        return bundle.request;
    }
};

Basically, action_fields and request are siblings in the bundle structure, not parent/child.