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

  • 25 January 2022
  • 0 replies
  • 2362 views
Dynamically Parse URL Query String Parameters into an Object with JavaScript Code
Userlevel 7
Badge +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

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.


0 replies

Be the first to reply!

Reply