JSON API : does not work when there is a field starting with a number - cloudpebble

Here is one field of the JSON API from accuweather :
data.list[i].rain.3h
It doesn't work when using Javascript (from cloudpebble). This line produces an error :
var rain =1;
rain = data.list[i].rain.3h;
The error is :
[PHONE] pebble-app.js:?: SyntaxError: Unexpected token ILLEGAL
[PHONE] pebble-app.js:?: JS failed.
The problem comes from the "3" because it works for all others field. Do you know a workaround to make it work ?
PS : API description is here (not sure you need it):
http://openweathermap.org/forecast5

Somebody gave me the solution : I can use this syntax to make it work when it starts with a digit :
rain=data.list[i].rain['3h']

Related

Unable to fetch entity by ID in B2WDigital RestQL NPM package

I don't know if I can ask this question in here or not.
I am using the NPM package #b2wdigital/restql in a Node.js server and everything is working fine with dummy APIs from the internet...
But when I used it to call our API it worked for calling many entities "for example ENDPOINT/cars" but not for one entity "for example ENDPOINT/car/:id".
I figured that the issue that because I am using the "#" character in the ID so it is ignored on the request.
I tried to encode URI component on it so to became "%23" the problem the library encodes also the "%" so the ID will contain "%2523" which does not exist.
I didn't find a solution for this.
My query is below (I am passing the values as parameters):
from car
headers
Authorization = $auth
with
id = $id
My mappings are:
{
"cars": "https://www.example.com/dev/cars",
"car": "https://www.example.com/dev/cars/:id"
}
Any help will be appreciated!

Docusign API PHP adding listitem to document causes error

I am sure I am not the first to encounter this, but I was unable to find a solution while Googling.
I am trying to add a drop-down list to my document. At the top of my model I am adding these namespaces:
use \DocuSign\eSign\Model\List;
use \DocuSign\eSign\Model\ListItem;
When doing so I get this error because "List" is a reserved word in PHP.
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected List (T_LIST), expecting identifier (T_STRING)
Filename: models/Docusign_model.php
Line Number: 19
I tried changing the name of the class from List to Elist but then I got errors from ObjectSerializer that it could not find Elist:swaggerType.
What am I missing on how to add a list to my document?
Thom
#thom I think this is really a "PHP" parsing question as is answered here for you Parse error: syntax error, unexpected (T_STRING), expecting variable (T_VARIABLE)
So I think the $ missing is your real issue as discussed in the referenced article above and below from PHP Manual.
http://www.php.net/manual/en/language.oop5.basic.php
Recommend you look at GIT example from SDK using CustomFieldList at https://github.com/docusign/docusign-php-client/blob/ccc86ac37334f34728361d73b2f8c4592225b8d2/src/Model/CustomFieldsEnvelope.php
excerpt
protected static $swaggerTypes = [
'list_custom_fields' => '\DocuSign\eSign\Model\ListCustomField[]',
'text_custom_fields' => '\DocuSign\eSign\Model\TextCustomField[]'
];
http://www.php.net/manual/en/language.oop5.basic.php
Also, maybe the first place to validate if you even need a specific "use" is by reviewing this PHP sample code from a good friend Ergin https://gist.github.com/Ergin008/d4a8b9210fbea41414b0
As I see it with most of the DocuSign SDK's, you have the client and specific services you want to use per excerpt below:
// Download PHP client: https://github.com/docusign/DocuSign-PHP-Client
require_once './DocuSign-PHP-Client/src/DocuSign_Client.php';
require_once './DocuSign-PHP-Client/src/service/DocuSign_RequestSignatureService.php';
require_once './DocuSign-PHP-Client/src/service/DocuSign_ViewsService.php';
Regardless if I am right or wrong, let us know if this helped you go in the right direction :-)

Kibana and groovy scripting

I was looking for a way to calculate a ratio on Kibana. After many researches i found this way :
Using the "JSON Input" feature in a visualisation.
I have all my informations in an index, with 2 types of documents (boots and reboots).
I am looking for the script which count the number of documents with the type boots, same for the reboots type then divide the second by the first.
It sounds really easy, but i do not find any way to get it after my researches, and i am not used to groovy enough yet to do it by myself.
I found many ways to manipulate documents values (doc['mydocname'].values etc), but nothing about the type.
Thanks in advance.
EDIT : I tried this
{
"aggs" : {
"boots_count" : { "value_count" : { "_type" : "boots" } }
}
}
Which is supposed to count the number of fields (here the field _type) in the index. But when i put it into "JSON Input" in a visualisation, that results in an error :
Error: Request to Elasticsearch failed: {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[BbXJ0O6tRxa_OcyBfYCGJQ][informationbe][0]: SearchParseException[[informationbe][0]: from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"aggs\":{\"2\":{\"terms\":{\"field\":\"#sitePoste\",\"size\":5,\"order\":{\"1\":\"desc\"}},\"aggs\":{\"1\":{\"avg\":{\"script\":\"0\",\"lang\":\"expression\",\"ratio\":{\"boots_count\":{\"value_count\":{\"_type\":\"boots\"}}}}}}}}
I am wrong. But where ?
EDIT2 : In other hand, i am trying scripted fields, with something like this using lucene expression :
doc['_type:boots'].count / doc['_type:reboots'].count
but it doesnt work more, i am pretty confident about the "doc['_type:boots']" part, i guess the problem is on the "XXX.count" part.
After many attempts, i understand better and better how it works. Default scripted fields scope is on the document, not on the whole index, so i cant do a count action of whole values of the index from documents in it.
I am looking for a workaround, i'll post it it if find something interesting.
I finally solved my problem :
I added a scripted field, if the type of the document is boots, the scripted field = 1, else 0. Then i created a search with only boots and reboots documents (filter _type:boots _type:reboots) and calculated the average of the scripted field in a metric.
Everything works well !

elastic search _bulk request with "head" plugin

I've an elastic search cluster with "elasticsearch-head" plugin installed properly.
I want to use the _bulk API to insert several values at once but the specific format of _bulk request body seems to be causing troubles to the plugin.
I use the "Any query" panel to specify my request with the following setup:
query: /_bulk
body:
{ "create" : { "_index" : "eco", "_type" : "usage" } }
{ "index": 1, name" : "my_value" }
I get the following when validating the json and the request won't be executed:
JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data
Does anyone knows if elasticsearch-head plugin can handle the _bulk API ?
Or is there something wrong with my request ?
elasticsearch-head plugin does not support _bulk, will cause JSON error...
hope the author can support it as soon as possible, you can submit an issue to this below website.
https://github.com/TravisTX/elasticsearch-head-chrome/issues
You are missing the quotes before name.
{ "index": 1, "name" : "my_value" }
Now 2021 Sep. 27, ES 7.15.0 .
I tried to use the "head" plugin send _bulk , it failed too.
but I found that using Postman or Curl , both are ok.
[PUT] http://localhost:9200/customer/external/_bulk
// Postman > Body > raw > JSON
{"index":{"_id":"1"}}
{"name":"a"}
{"index":{"_id":"2"}}
{"name":"b"}
Notice
Keep every json statement stay at each one line, do not expand them.
You need a blank line at the bottom.
With curl, you need save statements in a file, then #it:
$ curl -XPUT 'http://localhost:9200/customer/external/_bulk' -H "Content-Type:application/json" --data-binary #esSQL.json

Using 'querystring.parse' built-in module's method in Node.JS to read/parse parameters

Scenario:
Consider the following code:
var querystring = require('querystring');
var ParamsWithValue = querystring.parse(req._url.query);
Then I am able to read any query string's value.
E.g: If requested string is http://www.website.com/Service.aspx?UID=Trans001&FacebookID=ae67ea324
I can get the values of query string with codes ParamsWithValue.UID & ParamsWithValue.FacebookID respectively.
Issue: I am able to get the values of any number of parameters passed in the same way described above. But for second time onwards I am getting the following error in response on browser.
Error:
{"code":"InternalError","message":"Cannot read property 'query' of undefined"}
Question: What is wrong in the approach to read the query string from the URL.
Note: I don't want to use any frameworks to parse it. I am trying to depend on built-in modules only.
Update: It responds correctly when the value of any of the parameter is changed. But if the same values requested again from even different browser it throws same error.
I think you need req.url rather than req._url.
req.url is a string, if you want a URI instance use require('url').parse(req.url)
So, you should finally have:
var ParamsWithValue = querystring.parse(require('url').parse(req.url).query);
Edit: I corrected a typo in point 1, the last req.url -> req._url

Resources