How to use brackets in query string when building custom app?

Hi,
I am trying to build a custom app but I face an issue with one of my query string element.
The parameter key is “q[s]” for sorting. I face no error when using it but this parameter is not taken into account.

I guess it is because of the brackets.
I tried encoding the bracket but no luck either.

Here is my trigger module “Communication” json:

{
	// Request to API endpoint
	"url": "/users", // Relative to base URL
	"method": "GET",
	"headers": { }, // Additinal HTTP headers
	"qs": { // Query string
		"per": "50"
	},

	"pagination": {
		"qs": {
			"page": "{{pagination.page}}",
			"q[s]": "created_at+desc"
		}
	},

	// Response handling
	"response": {
		// Splits the array from API response into bundles.
		// See documentation at: https://docs.integromat.com/apps/app-blocks/api/pagination
		"iterate": "{{body.data}}", // Iterates "users" array from API response to split it into individual items.

		// New items search specification
		// See documentation at: https://docs.integromat.com/apps/app-structure/modules/trigger#response.trigger
		"trigger": {
			"type": "date", // Identifies trigger polling by date.
			"id": "{{item.id}}", // Identifies items by its property: "id".
			"date": "{{item.attributes.created_at}}", // Identifies items by its property: "created" date.
			"order": "asc" // Specifies in what order the remote API returns items.
		},

		"output": "{{item}}", // Outputs whole each iterated "item" object as separate bundle.
		"limit": "{{parameters.limit}}" // Limits number of output bundles as requested by user (even if API returns more items).
	}
}

Welcome to the Make community!

I’m not sure if using square brackets in a key is even allowed, this is completely not what anyone would expect given that square brackets are reserved characters that denote the start and end of an array.

Give these a try instead and let me know if they work or don’t:

"q\[s\]": "created_at+desc"
"q": [
  "s": "created_at+desc"
]
2 Likes

Hi @samliew,
Thank you for your answer.

I already tried escaping the bracket but I have a “Invalid escape character in string.json(261)” error in the web editor preventing me from saving the changes.

For your second proposition I am also having an error in the editor: “Expected comma”.

image

image

What about this?

"q": {
  "s": "created_at+desc"
}

If it doesn’t work I’m out of ideas.

2 Likes

@Marc_Ago

The “Expected comma” error is because in the json array it’s expecting a flat array of values or an array of objects "q": [{"s":"created_at+desc"}] etc

Cheers

Simon

2 Likes

@samliew It works in the editor even if I get a syntax warning. But does not work when using the API.

@Simon_Langham Your proposition is valid in terms of syntax but when using the module the API still does not take into account this parameter.

Thanks both for trying to help but I think I am gonna be stuck on that one.

1 Like

Without seeing your custom app it’s hard to know the best way forward tbh.

What I can tell you is that using GET requests in Make it will translate any querystring element unless you put it directly into the url rather than a QS field in a component. Not sure if it’s related to your issue but thought it worth mentioning.

Best of luck mate

Cheers

Simon

3 Likes

@Simon_Langham Actually it is quite helpful in my case. As my query string element is static I can pass it directly in the url rather than using the “qs” attribute.

For anyone facing the same issue in the future, I moved from the following config:

{
    "url": "/users",
	"qs": {
		"q[s]":"created_at+desc",
        "per": "50"
	},
    // ...
}

to that one:

{
    "url": "/users?q[s]=created_at+desc",
	"qs": {
         "per": "50"
	},
    // ...
}
4 Likes

@Marc_Ago

Awesome!

Glad you found a solution.

Cheers

Simon

2 Likes