InfluxDB: Query data from measurement via REST API - rest

I am using the REST API of InfluxDB
curl -s -XPOST -G influxdb_url:8086/query?pretty=true --data-urlencode "db=metrics" --data-urlencode "q=SHOW MEASUREMENTS WITH MEASUREMENT=~/a.b-c*/"
to retrieve the measurements available
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "measurements",
"columns": [
"name"
],
"values": [
[
"a.b-c"
],
[
"a.b-cd"
],
[
"a.b-cde"
],
[
"a.b-cdfg"
]
]
}
]
}
]
}
and then I trying to select all the data from one of them
curl -s -XPOST -G influxdb_url:8086/query?pretty=true --data-urlencode "db=metrics" --data-urlencode "q=SELECT * FROM "a.b-c""
and I am getting this error
{
"error": "error parsing query: found -, expected ; at line 1, char 18"
}
The exact same query works if I login the Influx instance
select * from "a.b-c"

The issue here is the use of the quotation mark " in the string where you specify your query. To properly include the quotation mark in your query you need to wrap the string in triple single quotes. In this particular case the correct way is the following:
curl -s -XPOST -G influxdb_url:8086/query?pretty=true --data-urlencode "db=metrics" --data-urlencode '''q=SELECT * FROM "a.b-c"'''
which in turn gives you a desired outcome. An example of a response using test dataset:
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "a.b-c",
"columns": [
"time",
"m",
"value"
],
"values": [
[
"2020-10-06T15:13:29.562248587Z",
"a",
0
]
]
}
]
}
]
}

Related

Option "wildcarded" for "jsonPropertyValueQuery" ctsquery causes the different results called via REST API or in Marklogic Query Console

We have local instance of Marklogic recently downloaded from docker hub with the following bash command:
docker run --name marklogic-test -d -it -p 8000:8000 -p 8001:8001 -p 8002:8002 \
-e MARKLOGIC_INIT=true \
-e MARKLOGIC_ADMIN_USERNAME=admin \
-e MARKLOGIC_ADMIN_PASSWORD='Areally!PowerfulPassword1337' \
marklogicdb/marklogic-db:10.0-9.4-centos-1.0.0-ea4
The "Documents" database contains only two documents:
sample1.json
{
"v1": "1234",
"v2": "ABCD",
"v3": "0123456789"
}
and sample2.json
{
"v1": "5678",
"v2": "EFGH",
"v3": "9876543210"
}
In case we will run the following XQuery in Query Console:
xquery version "1.0-ml";
let $query := cts:and-query((
cts:directory-query("/", "infinity"),
cts:json-property-value-query("v3", "01*", ("wildcarded", "whitespace-sensitive", "punctuation-sensitive"))
))
return (xdmp:to-json($query), cts:search(/,$query))
The result will be expected... It will return only one document:
{
"andQuery": {
"queries": [
{
"directoryQuery": {
"uris": [
"/"
],
"depth": "infinity"
}
},
{
"jsonPropertyValueQuery": {
"property": [
"v3"
],
"value": [
"01*"
],
"options": [
"punctuation-sensitive",
"whitespace-sensitive",
"wildcarded",
"lang=en"
]
}
}
]
}
}
json as
JSON
{
"v1": "1234",
"v2": "ABCD",
"v3": "0123456789"
}
But if I will do the REST API request:
curl --location --request POST 'http://localhost:18000/LATEST/search?format=json' --user 'admin:Areally!PowerfulPassword1337' --header 'Content-Type: application/json' --data-binary "#test_api.json"
where the test_api.json has the following content:
{
"search": {
"ctsquery": {
"andQuery": {
"queries": [
{
"directoryQuery": {
"uris": [
"/"
],
"depth": "1"
}
},
{
"jsonPropertyValueQuery": {
"property": [
"v3"
],
"value": [
"01*"
],
"options": [
"punctuation-sensitive",
"wildcarded",
"whitespace-sensitive",
"lang=en"
]
}
}
]
}
},
"options": {
"return-plan": false,
"return-metrics": true,
"return-facets": true,
"return-query": false,
"transform-results": {
"apply": "raw"
},
"page-length": 10
}
}
}
The answer is like that:
{
"snippet-format": "snippet",
"total": 2,
"start": 1,
"page-length": 10,
"results": [
{
"index": 1,
"uri": "/sample1.json",
"path": "fn:doc(\"/sample1.json\")",
"score": 0,
"confidence": 0,
"fitness": 0,
"href": "/v1/documents?uri=%2Fsample1.json",
"mimetype": "application/json",
"format": "json",
"matches": [
{
"path": "fn:doc(\"/sample1.json\")/object-node()",
"match-text": [
"1234 ABCD 0123456789"
]
}
]
},
{
"index": 2,
"uri": "/sample2.json",
"path": "fn:doc(\"/sample2.json\")",
"score": 0,
"confidence": 0,
"fitness": 0,
"href": "/v1/documents?uri=%2Fsample2.json",
"mimetype": "application/json",
"format": "json",
"matches": [
{
"path": "fn:doc(\"/sample2.json\")/object-node()",
"match-text": [
"5678 EFGH 9876543210"
]
}
]
}
],
"metrics": {
"query-resolution-time": "PT0.000624S",
"snippet-resolution-time": "PT0.005684S",
"total-time": "PT0.00713S"
}
}
For some reason both documents are returned as result!
Even though "confidence" is 0.
How to understand that behavior of MarkLogic searching engine?
Is it a bug of Marklogic REST API or is there something we are missing?
In Query Console, look at the difference when applying the "filtered" vs. "unfiltered" option to your search.
MarkLogic REST API is an "unfiltered" query.
cts:search() by default is a "filtered" query.
A filtered search (the default). Filtered searches eliminate any false-positive matches and properly resolve cases where there are multiple candidate matches within the same fragment. Filtered search results fully satisfy the specified cts:query.
https://docs.marklogic.com/guide/performance/unfiltered#id_89797
An unfiltered search omits the filtering step, which validates whether each candidate fragment result actually meets the search criteria. Unfiltered searches, therefore, are guaranteed to be fast, while filtered searches are guaranteed to be accurate. By default, searches are filtered; you must specify the "unfiltered" option to cts:search to return an unfiltered search.

PayPal v2 Onboarding error with multiple products

I'm trying integrate PayPal V2 Onboarding in sandbox.
My call is :
curl -v -X POST https://api-m.sandbox.paypal.com/v2/customer/partner-referrals \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <My-Access-Token> " \
-d '{
"tracking_id": "795_123",
"operations": [
{
"operation": "API_INTEGRATION",
"api_integration_preference": {
"rest_api_integration": {
"integration_method": "PAYPAL",
"integration_type": "THIRD_PARTY",
"third_party_details": {
"features": [
"PAYMENT",
"REFUND"
]
}
}
}
}
],
"products": [
"EXPRESS_CHECKOUT",
"PPPLUS"
],
"legal_consents": [
{
"type": "SHARE_DATA_CONSENT",
"granted": true
}
]
}'
And the response is :
{
"name": "INVALID_REQUEST",
"message": "Request is not well-formed, syntactically incorrect, or violates schema.",
"debug_id": "266c1b0e09a8f",
"information_link": "",
"details": [{
"issue": "INVALID_ARRAY_LENGTH",
"description": "The number of items in an array should not be more than 1",
"field": "/products",
"location": "body"
}],
"links": []
}
Has anyone come up to this error message for "products" array, or is this a PayPal v2 Onboarding bug?

FIWARE Orion: return subscription id

When creating a subscription, it would be nice to return the subscription ID.
For instance, the following code doesn't return anything :
curl localhost:1026/v2/subscriptions -s -S --header 'Content-Type: application/json' \
-d #- <<EOF
{
"description": "A subscription to get info about Room1",
"subject": {
"entities": [
{
"id": "Room1",
"type": "Room"
}
],
"condition": {
"attrs": [
"pressure"
]
}
},
"notification": {
"http": {
"url": "http://localhost:1028/accumulate"
},
"attrs": [
"temperature"
]
},
"expires": "2040-01-01T14:00:00.00Z",
"throttling": 5
}
EOF
In the subscription case, the resource id is generated server-side (with difference to the entities endpoint, where the id is decided client-side).
It would be nice to return it in the POST call, is there any way to do this?
Subscription ID is retrieved in Location header in the response to the subscription creation request, eg:
Location: /v2/subscriptions/5b991dfa12f473cee6651a1a
More details in the NGSIv2 API specification (check "Create Subscription" section).

Read facebook lead ads - only one lead in response

I test on https://developers.facebook.com/tools/explorer/
My query: /v2.8/11111111/leadgen_forms?fields=leads_count,leads
Response:
{ "data": [
{
"name": "My Form",
"leads_count": 37,
"leads": {
"data": [
{
"created_time": "2016-12-21T14:50:56+0000",
"id": "10000000000000",
"field_data": [
{
"name": "email",
"values": [
"hidden#gmail.com"
]
},
{
"name": "first_name",
"values": [
"Hidden"
]
},
{
"name": "last_name",
"values": [
"Hidden"
]
}
]
}
],
"paging": {
"cursors": {
"before": "MTc0ODU4Mjg2MjEyODQ1MgZDZD",
"after": "MTc0ODU4Mjg2MjEyODQ1MgZDZD"
}
}
},
"id": "10000000000000"
}
}
Why I get only one lead in data, when I have 37 in leads_count field?
I actually don't see the way you are accessing leads documented anywhere.
In your request, you are accessing the edge of a page, requesting the forms, and within that, requesting the leads.
You should probably be using the edge of the form ID instead to retrieve leads:
curl -G \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.8/<FORM_ID>/leads
You can also filter them:
curl -G \
-d "filtering=[{'field':'time_created','operator':'GREATER_THAN','value':<TIMESTAMP>}]" \
-d "access_token=<ACCESS_TOKEN>" \
https://graph.facebook.com/<API_VERSION>/<AD_ID>/leads

Orion doesn't notify Cygnus

I followed the official documentation about cygnus and orion. All generic enablers are deployed correctly, without errors in their log files. But something strange happens, Orion never notifies Cygnus.
To test this mechanism I followed the example with Car entity provided in the official documentation.
My entity creation bash script:
(curl $1:1026/v1/updateContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d #- | python -mjson.tool) <<EOF
{
"contextElements": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1",
"attributes": [
{
"name": "speed",
"type": "integer",
"value": "75"
},
{
"name": "fuel",
"type": "float",
"value": "12.5"
}
]
}
],
"updateAction": "APPEND"
}
EOF
My entity subscription bash script:
(curl $1:1026/v1/subscribeContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Fiware-Service: vehicles' --header 'Fiware-ServicePath: /4wheels' -d #- | python -mjson.tool) <<EOF
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1"
}
],
"attributes": [
"speed",
"oil_level"
],
"reference": "http://$2:5050/notify",
"duration": "P1M",
"notifyConditions": [
{
"type": "ONCHANGE",
"condValues": [
"speed"
]
}
],
"throttling": "PT1S"
}
EOF
My entity update bash script:
(curl $1:1026/v1/updateContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d #- | python -mjson.tool) <<EOF
{
"contextElements": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1",
"attributes": [
{
"name": "speed",
"type": "integer",
"value": $2
}
]
}
],
"updateAction": "UPDATE"
}
EOF
Note: Orion responds to all requests.
After executing these scripts, cygnus must receive reported information from orion and save it in the database, but nothing happens.
Neither in /var/log/cygnus/cygnus.log file or in /var/log/contextBroker/contextBroker.log file are reported any information about orion notification.
Note: If I use the notify.sh script provided in the official documentation, Cygnus works well and saves all data in the database.
Note: I read in other questions problems about open ports but those don't apply to mine.
EDIT 1
After I subscribe the orion, the response is:
{
"subscribeResponse": {
"duration": "P1M",
"subscriptionId": "563e12b4f4d8334d599753e0",
"throttling": "PT1S"
}
}
And when I update anentity, orion returns it:
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "speed",
"type": "integer",
"value": ""
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
To GET entity from orion I used the following script:
(curl $1:1026/v1/queryContext -s -S --header 'Content-Type: application/json' \
--header 'Accept: application/json' -d #- | python -mjson.tool) <<EOF
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1"
}
]
}
EOF
Response:
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "fuel",
"type": "float",
"value": "12.5"
},
{
"name": "speed",
"type": "integer",
"value": "123"
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Note The speed value was updated with success.
Taking into account the Fiware-Service and Fiware-ServicePath headers in subscription request, it has been performeed in the "/4wheels" service path of the service "vehicles". However, entity creation request doesn't use such headers, so it is created in the default service path ("/") of the default service. Thus, the subscription is not "covering" the entity, so updates in the entity are not triggering notifications.
One solution to the problem would be to create the entity in the same service and service path of the subscription, i.e. "/4wheels" service path of the service "vehicles".
Please, check Orion official documentation about service and service path concepts.