Cannot bind query parameter; Unknown name basicRequest when retrieving basic insights for a location - google-my-business-api

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!

Related

Adding dynamic path parameters into Orbeon Form HTTP Service

I'm trying to add a dynamic path parameter into an HTTP service in Orbeon forms, ie call a specific URL based on the content of a form field. I know we can change the query string parameters but I need to change the URL itself - the one in this field:
I've read that this is possible in newer version of Orbeon forms by using
{fr:control-string-value('testField')}
but we are stuck on an older version.
I saw another question on Stack Overflow from a few years ago: Orbeon Form HTTP Service where #ebruchez explained xpath is executed in the Resource URL field and gave the example:
http://localhost/RESTFUL/GETADDRESS/{/*/bar/foo}
However, I can't get this to work.
I have been able to successfully execute XPath, eg:
{string-join("test", "value")}
But I don't seem to be able to work out the correct Xpath syntax to dynamically select the value of a sample field and insert it into this box. I think I'm missing something in how I construct the XPath to retrieve the value.
This is what I've tried so far:
{xxf:value('testField')}
{xxf:value($testField)}
{fr:control-value($testField)}
{fr:control-value('testField')}
{xxf:property('testField')}
{xxf:property($testField)}
{$testField}
{'testField'}
{xxf:get-request-parameter('testField')}
{xxf:bind('testField')}
{/*/testField/}
{/*/content/testField/}
{//testField/}
{//*:testField/}
{//:testField/}
{(//testField)[1].text()}
{//form/content/testField/text()}
{(//testField)[1]/text()}
If anyone has any hints of advice on what I'm doing wrong or could give me an example of the syntax I put in here to retrieve a value, I'd be eternally grateful.
You can use AVT (Attribute Value Templates) https://doc.orbeon.com/xforms/core/attribute-value-templates?q=avt. In resource in <xf:submission> or HTTP service wizard use e.g. {instance('fr-form-instance')//url} or if you want edit only some part of URL you can use http://httpbin.org/{instance('fr-form-instance')//url}. I make simple form for you https://demo.orbeon.com/demo/fr/orbeon/builder/edit/18c4bee259fd9f398238b3c72041ee43ea691aa7 witch save respose to dataset and have second example in resource.
Hope this help you

Passing hidden params into url

I have a rails application in which I would like to generate a url based on a parameter, but for that parameter to be hidden from public view. So essentially working like a POST request but being able to be typed in like a GET request.
For example using a QR reader I could have the address as www.site.com/qr?lot_no=18007 but when a user scans the QR image it only shows www.site.com/qr but displays the results related to lot_no=18007.
Not sure if this is possible or not. But any help would be greatly appreciated.
If all you want to do is to prevent it from showing up in the address bar of the browser, you could use Rails.ajax to make the request dynamically through Javascript.
That will at least hide it from casual inspection, but there is no way to suppress the parameters from the query string on a GET completely, so anyone looking at the Networks tab in the browser (for example) would still see them.
Another alternative would be to encrypt the parameter value.
Maybe the Friendly id gem may be of help here
The following is an example of it's use is
http://example.com/states/washington
instead of:
http://example.com/states/4323454
This is not going to work with a post request as you mention though. It is a way of using a get request that would normally send an id in the params hash to retrieve existing records.
The gem can be found here https://github.com/norman/friendly_id
It is well maintained and up to date
Configure different route for public facing URL, the URL should include encrypted lot id as a path param.
routes.rb
get '/view_lot/:id' => 'QrCodesController#view_lot`, as: :public_view_lot
now in QrCodesController add action view_lot
def view_lot
encrypted_id = params[:id]
id = decrypt_it(encrypted_id)
#lot = Lot.find(id)
render "your_template"
end
in you QR code generation, pass URL to above action with encrypted id like public_view_lot_url(lot_id)

Different result when using GET/POST in elastic search

I am experimenting with elastic search via the Elastic Search Head plugin.
The results are as expected when I submit a query via POST.
However when I try the same query using GET, I always get back all values in the index.
So : how to pass the query to the elastic search server via GET so I can use the search string in an URL?
If you send a GET the body is probably not even sent to elasticsearch, so you are basically sending no query to the _search endpoint, which is why you are getting everything back (of course only the first 10 results based on the default size parameter).
Have a look at the URI request, which allows you to send basic queries using the q parameter within the URI. You can use the Lucene query syntax and specify some other parameters listed in the linked page. If you then want to execute more advanced queries, you might want to express them as JSON queries in order to get all the benefits of the elasticsearch Query DSL, but you'd need to provide them as body of the request.
UPDATE
Looking deeper at the elasticsearch head plugin, the query is not sent as the request body when you select the GET method but within the URL itself and without specifying the name for the parameter, like this:
http://localhost:9200/_search&{"query":{"term":{"text":"john"}}}
That is probably a bug in the plugin itself and elasticsearch can't find the query, that's why you get all the results back. That means that only the POST method works while sending queries with elasticsearch head.
Elasticsearch allows to use both GET and POST for executing queries. If you use GET you can either send the query as body or use the source parameter like this:
http://localhost:9200/_search?source={"query":{"term":{"text":"john"}}}

Extracting JSON data from node?

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"]

URL length limit for google reader api

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.

Resources