question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Base string incorrect for array type GET query string

See original GitHub issue

It seems that array type GET query strings aren’t quite supported.

e.g.

// request_data.data
{ 
  filter: [ { attribute: 'updated_at', from: '2017-05-10 00:00:00' } ],
  limit: 100,
  page: 1 
}

If you url encode this with something like qs, then you would get

filter%5B0%5D%5Battribute%5D=updated_at&filter%5B0%5D%5Bfrom%5D=2017-05-10%2000%3A00%3A00&limit=100&page=1

or in other words

filter[0][attribute]=updated_at&filter[0][from]=2017-05-10 00:00:00&limit=100&page=1

Which is a valid query string.

However, when the module is getting the Base string from this, the parameter string comes out like so

filter%3D%255Bobject%2520Object%255D%26filter%25255B0%25255D%25255Battribute%25255D%3Dupdated_at%26filter%25255B0%25255D%25255Bfrom%25255D%3D2017-05-10%252000%253A00%253A00%26limit%3D100%26page%3D1

Which decodes to

filter=[object Object]&filter[0][attribute]=updated_at&filter[0][from]=2017-05-10 00:00:00&limit=100&page=1

So as you can see it is nearly correct but the filter=[object Object]& breaks it. Is there some other way I should be passing in the filter array to make this work like qs? If I omit the filter parameter, then the signature works fine with the other params.

Hopefully I’ve explained myself well enough, thanks

If you are wondering, the filters in this format are expected by Magento’s REST API http://devdocs.magento.com/guides/m1x/api/rest/get_filters.html

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dinoboffcommented, Dec 22, 2017

IMHO, OAuth-1.0a is a low level library and should not try to encode complex object; there’s many way to encode them and there’s no way to ensure the http client encoding will match OAuth-1.0a one. The solution would be to encode the data first, or let the http client encode it, and provide the encoded data to OAuth-1.0a. OAuth-1.0a would have to parse it like it parses the query string.

An alternative would be to add a data_encoder option to override the default simple encoder.

ps: probably encoder is not right word.

0reactions
ddocommented, Jun 5, 2019

for complicated object data, you should turn it to json string JSON.stringify(data) then send it as a string.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parse query string in JavaScript [duplicate] - Stack Overflow
Here is a fast and easy way of parsing query strings in JavaScript: function getQueryVariable(variable) { var query = window.location.search.substring(1); ...
Read more >
Array or List in query string does not get parsed #10323 - GitHub
Everything is parsed, except for the List type values, so: AppliedFilters (that then contains a List<object> ).
Read more >
http_build_query - Manual - PHP
Generates a URL-encoded query string from the associative (or indexed) array provided. Parameters ¶. data. May be an array or object containing properties....
Read more >
REST API Design Best Practices for Parameter and Query ...
Best practices for parameter and query string usage in REST APIs. ... While HTTP verbs and resource URLs allow for some basic interaction, ......
Read more >
Error "Invalid value for query parameter" and failed to send a ...
Learn how to send a proper request with array query parameters with ... /test: get: queryParameters: ids: type: array items: type: string ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found