Skip to main content

Dynamically Parse URL Query String Parameters into an Object with JavaScript Code

  • 25 January 2022
  • 3 replies
  • 2853 views
Dynamically Parse URL Query String Parameters into an Object with JavaScript Code
Troy Tessalone
Forum|alt.badge.img+14

📌  We do our best to ensure that the code in these articles works as advertised, but please be aware that Zapier Support does not officially help with code steps due to their advanced nature. Feel free to comment on the article or ask in the Zapier Community, where we have code-savvy users.

 

How to Configure 

Here’s how to set up the Code by Zapier step (using the Javascript option):

 

Copy the Code

Show content
let url = inputData.url;
let base = url.split("?").shift();
let querystring = url.split("?").pop();
let params = querystring.split("&");
let pairs = {};

for (let i = 0; i < params.length ; i++) {
  let key = params[i].split("=").shift();
  let value = params[i].split("=").pop();
  pairs[key] = value;
}

output = [{url, base, querystring, params, pairs}];

 

 

The Results

And here is what the code step will produce:

 

Contribution by Troy Tessalone

Troy is a Certified Zapier Expert who automates workflows with no-code and low-code apps to help clients save time and make money.

Did this topic help you find an answer to your question?
67% found this helpful

  • Beginner
  • October 25, 2024

Is there a character limit for the inputData.url or querystring? We are noticing in some of our zaps that the query string output is truncated to around 210 characters.


Troy Tessalone
Forum|alt.badge.img+14

@KGib 

For us to have more info, we would need to see specific examples. (url + screenshots)


  • Beginner
  • October 29, 2024

It looks like the URLs that are transmitted to Zapier from our Chat provider have a character limit, so it appears to be happening prior to Zapier processing the data. We are working with our chat provider to resolve.


Reply