I'm a couchDB newb and I'm trying to grab a large subset of documents by passing an array of keys.
Example: https://my.db/docs/_all_docs?include_docs=true&key=[long array of keys here]
Turns out my key array is too long so I get 400 bad request returned by Apache.
Is there a way I can do a post to that URL and send the keys as post data??
Use POST request method with specified list of keys in the body. It was specially designed to resolve problem like you got.
Related
I'm trying to retrieve insights for a location using the Google Business Profile API. I've tried a few approaches, but I always get an error about "Cannot bind query parameter".
According to the docs, I should be posting to this URL: https://mybusiness.googleapis.com/v4/accounts/xxx/locations:reportInsights
and in the body, pass in an array of locationNames, but when I do that, I get the error about "Cannot bind query parameter 'locationNames'".
So I just tried doing a GET on this URL and pass in the names on the name querystring and that worked just fine to get the high-level data.
https://mybusiness.googleapis.com/v4/accounts/xxx/locations:reportInsights?name=accounts/xxx/locations/xxx
So I know I have the right account ID, location ID, etc. But I need to be able to add in the basicRequest parameter so I can indicate which metric that I want to retrieve.
So I've POST to both of those URLS above with a body that looks like this:
{"basicRequest":{"metricRequests":[{"metric":"ALL"}],"timeRange":{"startTime":"2020-10-12T01:01:23.045123456Z","endTime":"2022-01-10T23:59:59.045123456Z"}}}
But again, I get the same errors about "Cannot bind query parameter" to field "basicRequest" (Same as when I tried to pass in the "locationNames" param in the JSON.
So clearly, I'm doing something wrong with how I am sending in the parameters in the body because it doesn't seem to think any of those parameter names are valid. My end goal is to be able to retrieve queries_direct, actions_total, etc.
I'm using Ruby, and there isn't a client library for it, so I'm just crafting the URLs and the JSON body and doing a GET or POST to it.
Greatly appreciate any pointers!
I've made a twitter api request (GET trends/place API) and the result is just like this:
[{"trends":[{"name":"#BabyIsStaying","url":"http:\/\/twitter.com\/search?q=%23BabyIsStaying","promoted_content":null,"query":"%23BabyIsStaying","events":null},{"name":"#AkTakipBa\u015fl\u0131yor","url":"http:\/\/twitter.com\/search?q=%23AkTakipBa%C5%9Fl%C4%B1yor","promoted_content":null,"query":"%23AkTakipBa%C5%9Fl%C4%B1yor","events":null},{"name":"#\u00c7apulcuTakip","url":"http:\/\/twitter.com\/search?q=%23%C3%87apulcuTakip","promoted_content":null,"query":"%23%C3%87apulcuTakip","events":null},{"name":"#SadeceKar\u015f\u0131l\u0131kl\u0131Takiple\u015fme","url":"http:\/\/twitter.com\/search?q=%23SadeceKar%C5%9F%C4%B1l%C4%B1kl%C4%B1Takiple%C5%9Fme","promoted_content":null,"query":"%23SadeceKar%C5%9F%C4%B1l%C4%B1kl%C4%B1Takiple%C5%9Fme","events":null},{"name":"#soysuzek\u015fis\u00f6zl\u00fck","url":"http:\/\/twitter.com\/search?q=%23soysuzek%C5%9Fis%C3%B6zl%C3%BCk","promoted_content":null,"query":"%23soysuzek%C5%9Fis%C3%B6zl%C3%BCk","events":null},{"name":"B\u00fcy\u00fck FENERBAH\u00c7E Taraftarlar\u0131Takiple\u015fiyor","url":"http:\/\/twitter.com\/search?q=%22B%C3%BCy%C3%BCk+FENERBAH%C3%87E+Taraftarlar%C4%B1Takiple%C5%9Fiyor%22","promoted_content":null,"query":"%22B%C3%BCy%C3%BCk+FENERBAH%C3%87E+Taraftarlar%C4%B1Takiple%C5%9Fiyor%22","events":null},{"name":"Sar\u0131K\u0131rm\u0131z\u0131Aile UnfollowsuzTakiple\u015fiyor","url":"http:\/\/twitter.com\/search?q=%22Sar%C4%B1K%C4%B1rm%C4%B1z%C4%B1Aile+UnfollowsuzTakiple%C5%9Fiyor%22","promoted_content":null,"query":"%22Sar%C4%B1K%C4%B1rm%C4%B1z%C4%B1Aile+UnfollowsuzTakiple%C5%9Fiyor%22","events":null},{"name":"D\u00fcnyadaTeksinSen GALATASARAY\u0131m","url":"http:\/\/twitter.com\/search?q=%22D%C3%BCnyadaTeksinSen+GALATASARAY%C4%B1m%22","promoted_content":null,"query":"%22D%C3%BCnyadaTeksinSen+GALATASARAY%C4%B1m%22","events":null},{"name":"D\u00fcnyan\u0131n TekHarikas\u0131s\u0131n FENERBAH\u00c7EM","url":"http:\/\/twitter.com\/search?q=%22D%C3%BCnyan%C4%B1n+TekHarikas%C4%B1s%C4%B1n+FENERBAH%C3%87EM%22","promoted_content":null,"query":"%22D%C3%BCnyan%C4%B1n+TekHarikas%C4%B1s%C4%B1n+FENERBAH%C3%87EM%22","events":null},{"name":"MustafaKemalin\u0130zindeyiz \u00c7\u00fcnk\u00fcFenerbah\u00e7eliyiz","url":"http:\/\/twitter.com\/search?q=%22MustafaKemalin%C4%B0zindeyiz+%C3%87%C3%BCnk%C3%BCFenerbah%C3%A7eliyiz%22","promoted_content":null,"query":"%22MustafaKemalin%C4%B0zindeyiz+%C3%87%C3%BCnk%C3%BCFenerbah%C3%A7eliyiz%22","events":null}],"as_of":"2013-07-20T10:51:45Z","created_at":"2013-07-20T10:45:24Z","locations":[{"name":"Turkey","woeid":23424969}]}]
My question is how to turn this array string into html. No proper php experience at all.
The response you are getting is JSON.
You used to be able to get response in XML, RSS and more, but now the only response type you will receive is JSON.
PHP has multiple methods for dealing with JSON. To encode data, you would use json_encode(). However, you want to decode it, so you want to be doing the following:
var_dump(json_decode($yourData));
This will dump the data to the browser so you can see what you have to work with.
You can iterate around this data using a foreach() loop.
Remember, assuming you json_decode() your results into $yourData:
To access array properties, use: $yourData['propertyName']
To access object properties, use: $yourData->propertyName
you can feed that into json_decode() function
you will get an array that you can manage as you want.
How do I pass array of parameters through Get method in rails? Currently my URL loocs like this:
http://localhost:3000/jobs/1017/editing_job_suites/1017/editing_member_jobs/new?ids[]=1025&ids[]=1027
How can I pass the array with Get method but avoid ?ids[]=1025&ids[]=1027 part.
Request is being sent with javascript window.open method. Is there any workaround to send not ajax Post request.
You should stick to using a GET request if you are not changing the state of anything, and all you want to to access a read only value.
To send an array of ids to rails in a GET request simply name your variable with square brackets at the end.
//angular snippet
$http.(method:'GET',
...
params: {'channel_id':2, 'product_ids[]': productIds}
//where productIds is an array of integers
...
)
Do not concatenate your ids as a comma separated list, just pass them individually redundantly. So in the url it would look something like this:
?channel_id=2&product_ids[]=6900&product_ids[]=6901
url encoded it will actually be more like this:
?channel_id=2&product_ids%5B%5D=6900&product_ids%5B%5D=6901
Rails will separate this back out for you.
Parameters: {"channel_id"=>"2", "product_ids"=>["6900", "6901"]}
No, GET can only put variables on the url itself. If you want the URL to be shorter, you have to POST. That's a limitation feature of HTTP, not Rails.
I recently wanted to do this and found a workaround that is a little less complex, and so has some complexity limitations but may also be easier to implement. Can't speak to security, etc.
If you pass your array values as a string with a delimiter, e.g.
http://example.com/controller?job_ids=2342,2354,25245
Then you can take the result and parse it back to what you want:
job_ids = params[:job_ids].split(',')
Then do whatever:
job_ids.each do |job_id|
job = Job.find(job_id.to_i)
end
etc
#Homan answer is valid for using an external client (e.g curl or angular). Inside Rails test cases though, you should not use []. Here's an example:
get get_test_cases_url(**path_params), params: {case_ids: ["NON-9450", "NON-12345", "NON-9361"]}
This is using new format where get_test_cases is name of route and you pass to the method all params needed to construct the URL path. Query params are a separate hash.
FYI if I use [] like case_ids[], then instead of ["NON-9450", "NON-12345", "NON-9361"] I'm getting it parsed to [["NON-9450"], ["NON-12345"], ["NON-9361"]]
With a request to Twitter for example:
https://api.twitter.com/1/users/show.json?screen_name=stephenfry&include_entities=true
I can extract an element like followers_count using result["followers_count"]
I've tried a similar request to LastFM but their JSON is structured differently as it's a translation of their default XML.
With their demo request:
http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=b25b959554ed76058ac220b7b2e0a026&format=json
How would I get the listeners value?
I've tried
result["listeners"]
result["artist.listeners"]
result["artist.stats.listeners"]
I understand I need to access a node, but have no idea how to go about it.
Can anyone help?
It's a nested hash, so you can reach it with:
result["artist"]["stats"]["listeners"]
Example:
require('open-uri')
require('json')
result = JSON.parse(open('http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=b25b959554ed76058ac220b7b2e0a026&format=json').read)
result["artist"]["stats"]["listeners"].to_i
The Last.fm data is a series of nested hashes, so you need to access them as such. Give the following a try, it should do the trick:
result["artist"]["listeners"]
I am using "/reader/api/0/stream/items/ids" API to get the item ids for sources that I want.
I have quite a number of sources, so I repeated "s=" parameter to include in the api url.
However, google has given me an error of "URL is too long".
So the question is that How can I solve it so that I just use one time api call to get item ids for that many sources?
Thanks
It seems that /reader/api/0/stream/items/ids path supports a POST method. This means the amount of data you could pass by using POST verb is much more than by using a query string and a GET method.
So use https://www.google.com/reader/api/0/stream/items/ids URL for the post, and pass your query string as a post data. Don't forget to include an action token(T) which is required for POST requests.