Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GET request with unencoded queryparams #1645

Open
zero2411 opened this issue Sep 22, 2021 · 0 comments
Open

GET request with unencoded queryparams #1645

zero2411 opened this issue Sep 22, 2021 · 0 comments

Comments

@zero2411
Copy link

I'm using NodeJS with Superagent to connect to an API.
The URL should look like this:

https://example.com/api/schedule/default/events?query={"jobSourceIds":["614999492641e60d523e1f51"],"status":["ready","notstarted"]}

I've tested this URL in Postman and it works fine.

But Superagent transforms this to:

https://example.com/api/schedule/default/events?query=%7B%22jobSourceIds%22:[%22614999492641e60d523e1f51%22],%22status%22:[%22ready%22,%22notstarted%22]%7D

The query-params are encoded which I don't want since my API can't process it.
The API ignores the params this way.

The queryParams are provided as a string in the right form.

I've tried to set the Content-type and request.type to JSON, but no luck.

Any suggestions on how to get this right?

var request = superagent[method.toLowerCase()](baseUrl + path);
request.set("Accept", "application/json");
request.set("Cache-Control", "no-cache");
// request.set('Content-Type', 'application/json')
request.set('Content-Type', 'application/x-www-form-urlencoded')

var headers = createHeaders(method, path);
  Object.keys(headers).forEach(function (k) {
  request.set(k, headers[k]);
});

request.proxyWrapper = function (proxy) {
if (proxy == undefined) return this;
  return this.proxy(proxy);
};

console.log(queryParams)        // query={"jobSourceIds":["614999492641e60d523e1f51"],"status":["ready","notstarted"]}
console.log(typeof queryParams) // string
return request.send(payload).query(queryParams).proxyWrapper(proxy).end(responseHandler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant