HTTP Request - passing a parameter with multiple values

Hi there,

First of all - really great tool and amazing to see the development progressing so well!

I am a beginner here and trying to create a simple request to test the performance of my webpage with Google PageSpeed Insights API. I have the nodes working, data is being returned from Google PSI, however, I am facing an issue with setting the parameters for this request.

Google PageSpeed Insights API Doc - Method: pagespeedapi.runpagespeed  |  PageSpeed Insights  |  Google Developers

I need to execute the following API call (removed key and domain for privacy reasons):

https://pagespeedonline.googleapis.com/pagespeedonline/v5/runPagespeed?url=[MY_WEBPAGE]&category=PERFORMANCE&category=ACCESSIBILITY&category=BEST_PRACTICES&category=SEO&locale=en-GB&strategy=DESKTOP&prettyPrint=true&fields=lighthouseResult%2Fcategories%2F*%2Fscore&key=[MY_KEY]

In short, in this one API call, I need to pass 1 parameter (&category=) multiple times, but with different values (&category=PERFORMANCE&category=ACCESSIBILITY&category=BEST_PRACTICES&category=SEO).

I’ve configured the node with JSON/RAW query parameters as follows:

{
"url": "{{$node["MongoDB"].json["url_checked"]}}",
"category": "accessibility",
"category": "best-practices",
"category": "performance",
"category": "seo",
"locale": "en-GB",
"strategy": "DESKTOP",
"prettyPrint": true
}

For some reason, when n8n submits this query, it actually overwrites all category values with the last one provided. Unfortunately, it is not possible to pass the values as an array (using their API explorer, they just append the same parameter with different values multiple times).

Is this potentially a bug in n8n or intended behavior? It does seem weird that Google doesn’t support passing the parameters in the array but not much I can do in that regard. Many thanks in advance!

Hi @vnmdr-ap, welcome to the community!

While https://www.ietf.org/rfc/rfc4627.txt suggest the names within a JSON object should be unique, I can see how this would be a pain with this specific API.

Would just putting the query parameters in the URL itself work in your case? So essentially making a request to https://pagespeedonline.googleapis.com/pagespeedonline/v5/runPagespeed?category=one&category=two and ignoring the query parameters field of the HTTP Request node for the category parameter?

1 Like

Hi @MutedJam, thanks for a warm welcome!

And thanks for the solution, just tested and it worked! Haven’t thought of putting them into the URL directly. I’ve just appended those “&category=” parameters to the URL, leaving the rest in the JSON object, which then resulted in the combined string that makes everything work.

Thanks again!

2 Likes

Glad to hear this works for you, thanks so much for confirming and have a nice Friday :slight_smile: