Google spreadsheets.create with merged cells - google-apis-explorer

Create google spreadsheets api test on: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create
{
"sheets": [
{
"merges": [
{
"sheetId": 0,
"startColumnIndex": 0,
"startRowIndex": 0,
"endColumnIndex": 12,
"endRowIndex": 3
}
]
}
]
}
So i tried using google spreadsheets create with merged cells but it returned an error of:
{
"error": {
"code": 400,
"message": "Invalid sheets[0].merges[0]: No grid with id: 0",
"status": "INVALID_ARGUMENT"
}
}
Anyone know where I got it wrong? Thank you.

How about this request body? It sets sheetId for properties.
{
"sheets":
[
{
"merges":
[
{
"sheetId": 0,
"startColumnIndex": 0,
"startRowIndex": 0,
"endColumnIndex": 12,
"endRowIndex": 3
}
],
"properties":
{
"sheetId": 0
}
}
]
}
Reference :
SheetProperties

Related

read json data from text file according to my conditions

here is my jason text file containing more than two json object having different policyNumber i want to read data on the base of policyNumber or may be another value and it show only those json object having same parameters that i request or say same policy number i sent to them.
I am working on API so i have no idea about this and i am also fresher in it field
no idea about how to return values.
plese guide and thanks in advance
my jason text file contain
{
"jsonData": {
"PolicyValue": {
"PolicyNumber": "003",
"EffectiveDate": "2022-09-14",
"MCV_NetBaseCashValue": 9700,
"Dividend": 0,
"DividendsInterest": 0,
"CouponBalance": 0,
"CouponBalancesInterest": 0,
"BaseCashValue": 700,
"CashSurrenderValue": 00,
"APLAmount": 0,
"APLAmountsInterest": 0,
"OPLAmount": 0,
"OPLAmountsInterest": 0,
"MiscellaneousSuspense": 0,
"PremiumSuspense": 0,
"OutstandingDisbursement": 0,
"SurrenderCharge": 0
}
},
"reponseCode": "00",
"reponseMessage": ""
}
{
"jsonData": {
"PolicyValue": {
"PolicyNumber": "123",
"EffectiveDate": "2022-08-17",
"MCV_NetBaseCashValue": -100,
"Dividend": 0,
"DividendsInterest": 0,
"CouponBalance": 0,
"CouponBalancesInterest": 0,
"BaseCashValue": 100,
"CashSurrenderValue": -100,
"APLAmount": 0,
"APLAmountsInterest": 0,
"OPLAmount": 0,
"OPLAmountsInterest": 0,
"MiscellaneousSuspense": 0,
"PremiumSuspense": 0,
"OutstandingDisbursement": 0,
"SurrenderCharge": 200
}
},
"reponseCode": "00",
"reponseMessage": ""
}
this is my first file
and my second file is
{
"jsonData": {
"PolicyNumber": "354",
"PolicyCommencementDate": "2020-07-31",
"InsuranceDetails": [ {
"PolicyNumber": "54",
"ClientID": "04",
"InsuredFirstName": "LEÄ",
"InsuredLastName": "HAÈNG",
"InsuredDOB": "1978-01-01"
},
{
"PolicyNumber": "54",
"ClientID": "09",
"InsuredFirstName": " YEÂN",
"InsuredLastName": "NG",
"InsuredDOB": "2006-11-08"
} ]
},
"reponseCode": "00", "reponseMessage": ""
}
{
"jsonData": {
"PolicyNumber": "737",
"PolicyCommencementDate": "2019-07-25",
"InsuranceDetails": [
{
"PolicyNumber": "37",
"ClientID": "15",
"InsuredFirstName": "N HAÛI",
"InsuredLastName": "ANH",
"InsuredDOB": "1989-10-04"
},
{
"PolicyNumber": "37",
"ClientID": "25",
"InsuredFirstName": "NH",
"InsuredLastName": "AÁN",
"InsuredDOB": "1988-01-04"
},
{
"PolicyNumber": "37",
"ClientID": "26",
"InsuredFirstName": "RUÙC",
"InsuredLastName": "DNG",
"InsuredDOB": "2021-05-17"
}
]
},
"reponseCode": "00",
"reponseMessage": ""
}
i want to apply on the base of get request please solve this issue as soon as possible
i teried this code in my value controller
public class ValuesController : ApiController
{
string[] fileConten = Directory.GetFiles(HostingEnvironment.MapPath(#"~/Documents/V1/policy/seachpolicy"));
public string Get()
{
string writeResult = string.Empty;
string strr = File.ReadAllText(fileConten[2]);
JObject jsonObj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(strr);
var jobj = JObject.Parse(jsonObj.ToString());
foreach (var item in jobj.Properties())
{
item.Value = item.Value["PolicyNumber"].ToString();
//item.Value = item.Value.SelectToken["PolicyValue"][0]["PolicyNumber"].ToString();
//item.Value = item.Value["PolicyNumber"][0]["InsuranceDetails"]["InsuredFirstName"].ToString();
int nm = Convert.ToInt32(item.Value);
if (nm == 008019354)
{
writeResult = jobj.ToString();
break;
}
break;
//item.Value = item.Value.ToString().Replace("0", "1");
}
return writeResult;
string output = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
return output;
this code not work properly
}

Calculate min and max from json data and store the result as list

I have data in JSON format, the sample is given below. I want to calculate the min and max range for the values inside the variable i.e. align_X, align_Y, align_Z.
{"id": 0, "variable": {"align_X": 41, "align_Y": 51, "align_Z": 80}}
{"id": 1, "variable": {"align_X": 0}}
{"id": 2, "variable": {"align_Y": 1, "align_Z": 0}}
Desired output is:
"align_X": [
0.0,
41.0
],
"align_Y": [
1.0,
51.0
],
"align_Z": [
0.0,
80.0
]
Any help is appropriated.
Thank you
Can you try this
var test = [{
"id": 0,
"variable": {
"align_X": 41,
"align_Y": 51,
"align_Z": 80
}
}, {
"id": 1,
"variable": {
"align_X": 0
}
}, {
"id": 2,
"variable": {
"align_Y": 1,
"align_Z": 0
}
}
]
var result = test.reduce((acc, cobj) => {
for (key in cobj.variable) {
if (acc[key]) {
if(acc[key][0] > cobj.variable[key]){
if(!acc[key][1]){
acc[key][1] = acc[key][0];
}
acc[key][0] = parseFloat(cobj.variable[key]).toFixed(2)
} else if(acc[key][1] == undefined || acc[key][1] < cobj.variable[key]){
acc[key][1] = parseFloat(cobj.variable[key]).toFixed(2)
}
}
else {
acc[key] = [];
acc[key].push(parseFloat(cobj.variable[key]).toFixed(2))
}
}
return acc;
}, []);
console.log(result);
My solution
#Your input
d = [{"id": 0, "variable": {"align_X": 41, "align_Y": 51, "align_Z": 80}},
{"id": 1, "variable": {"align_X": 0}},
{"id": 2, "variable": {"align_Y": 1, "align_Z": 0}}
]
#To store result float(-inf) smallest number in python & float(inf) is largest
output = {
"align_X" : [float('inf'),float('-inf')],
"align_Y" : [float('inf'),float('-inf')],
"align_Z" : [float('inf'),float('-inf')]
}
for item in d:
for each in output.keys():
try:
if item['variable'][each]<output[each][0]:
output[each][0] = item['variable'][each]
if item['variable'][each]>output[each][1]:
output[each][1] = item['variable'][each]
except:
continue
print(output)

Python3 google spreadsheet api batchUpdate Json formatting

I want to use google spreadsheet api batchUpdate to update different values with the same request.
In the documentation examples they use a dict to store the Json request but I need to set the same attribute (insertDimension) multiple times.
Here Google expected request
{
"requests": [
{
"insertDimension": {
"range": {
"sheetId": sheetId,
"dimension": "COLUMNS",
"startIndex": 2,
"endIndex": 4
},
"inheritBefore": true
}
},
{
"insertDimension": {
"range": {
"sheetId": sheetId,
"dimension": "ROWS",
"startIndex": 0,
"endIndex": 3
},
"inheritBefore": false
}
},
],
}
I tried using json.dumps
mydata = json.dumps('''
"requests": [{{"updateDimensionProperties": {"range": {"sheetId": 0,"dimension": "ROWS","startIndex": 0
"endIndex": 50
},
"properties": {
"pixelSize": 10
},
"fields": "pixelSize"
}
}
} ] ''')
but I receive this error message
"Invalid JSON payload received. Unknown name "": Root element must be a message."
Your request is invalid because it never says what kind of request it is: the insertDimension request. The correct form is
{
"requests": [
{
"insertDimension": {
# required fields at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest
}
},
{
"insertDimension": {
# required fields at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#InsertDimensionRequest
}
}]
}
By the way, one of the fields is inheritFromBefore, not inheritBefore

Ecobee: Response returning only partial results

Using Google Apps script to attempt to talk to my thermostat using the Ecobee API. In the below code, the value of json is "{ "status": { "code": 0, "message": "" } }". For the correct, full response, see the results of curl later in the question.
For some reason response is only getting the final element (status) out of the three results that are returned by the server (page, thermostatList, and status).
What am I missing?
Google Apps Script is as follows:
function getSettings() {
var response = fetchSettings();
var json = response.getContentText();
var data = JSON.parse(json);
// response, json, and data only show `status` result
}
function fetchSettings() {
try {
var headers = {
'Authorization': 'Bearer AUTH_TOKEN'
};
var payload = {
'selection' : {
'selectionType':'registered',
'selectionMatch': '',
'includeRuntime': 'true'
}
};
var options = {
'method': 'get',
'headers': headers,
'contentType': 'text/json',
'payload': JSON.stringify(payload);
};
var URL = 'https://api.ecobee.com/1/thermostat?format=json'
return UrlFetchApp.fetch(URL,options);
} catch(e) {
return e;
}
}
Using curl as follows:
curl -s -H 'Content-Type: text/json' -H 'Authorization: Bearer AUTH_TOKEN' 'https://api.ecobee.com/1/thermostat?format=json&body=\{"selection":\{"selectionType":"registered","selectionMatch":"",includeRuntime":true\}\}'
I get full results.
{
"page": {
"page": 1,
"totalPages": 1,
"pageSize": 2,
"total": 2
},
"thermostatList": [
{
"identifier": "12345",
"name": "Downstairs",
"thermostatRev": "160528163253",
"isRegistered": true,
"modelNumber": "athenaSmart",
"brand": "ecobee",
"features": "",
"lastModified": "2016-05-28 16:32:53",
"thermostatTime": "2016-05-28 11:57:00",
"utcTime": "2016-05-28 16:57:00",
"runtime": {
"runtimeRev": "160528165546",
"connected": true,
"firstConnected": "2015-08-20 21:57:53",
"connectDateTime": "2016-05-26 08:56:18",
"disconnectDateTime": "2016-05-26 00:00:00",
"lastModified": "2016-05-28 16:55:46",
"lastStatusModified": "2016-05-28 16:55:46",
"runtimeDate": "2016-05-28",
"runtimeInterval": 200,
"actualTemperature": 703,
"actualHumidity": 49,
"desiredHeat": 670,
"desiredCool": 810,
"desiredHumidity": 44,
"desiredDehumidity": 56,
"desiredFanMode": "on"
}
},
{
"identifier": "310166836750",
"name": "Upstairs",
"thermostatRev": "160528162656",
"isRegistered": true,
"modelNumber": "athenaSmart",
"brand": "ecobee",
"features": "",
"lastModified": "2016-05-28 16:26:56",
"thermostatTime": "2016-05-28 11:57:00",
"utcTime": "2016-05-28 16:57:00",
"runtime": {
"runtimeRev": "160528165523",
"connected": true,
"firstConnected": "2015-09-28 13:33:41",
"connectDateTime": "2016-05-26 08:55:35",
"disconnectDateTime": "2016-05-26 00:00:00",
"lastModified": "2016-05-28 16:55:23",
"lastStatusModified": "2016-05-28 16:55:23",
"runtimeDate": "2016-05-28",
"runtimeInterval": 201,
"actualTemperature": 712,
"actualHumidity": 49,
"desiredHeat": 600,
"desiredCool": 840,
"desiredHumidity": 36,
"desiredDehumidity": 60,
"desiredFanMode": "auto"
}
}
],
"status": {
"code": 0,
"message": ""
}
}
I think the problem is that UrlFetchApp doesn't support sending payload using the get method as a query string. I assume this is correct design for UrlFetchApp and poor design on the part of the Ecobee API. I made a kluge workaround by sending the JSON in a query string myself as follows.
var URL = 'https://api.ecobee.com/1/thermostat?body='+encodeURIComponent(JSON.stringify(payload));

Mongo $and query returning no results

How do I approach writing a query to return all the records matching both match.id and player.name for the following collection?
{
"match": {
"id": 1,
"event": {
"timestamp": "2015-06-03 15:02:22",
"event": "round_stats",
"round": 1,
"player": {
"name": "Jim",
"userId": 45,
"uniqueId": "BOT",
"team": 2
},
"shots": 0,
"hits": 0,
"kills": 0,
"headshots": 0,
"tks": 0,
"damage": 0,
"assists": 0,
"assists_tk": 0,
"deaths": 0,
"head": 0,
"chest": 0,
"stomach": 0,
"leftArm": 0,
"rightArm": 0,
"leftLeg": 0,
"rightLeg": 0,
"generic": 0
}
}
}
I've attempted it with both the following query statements, but had no luck -- they both return no results:
db.warmod_events.find( { $and: [ { "match.id": 1}, { "player.name": 'Jim' } ] } )
db.warmod_events.find( { $and: [ { "match.id": 1}, { "event": { "player.name": "Jim" } } ] } )
I'm pretty new to Mongo and any guidance and explanation would help a bunch -- truthfully I've chosen to use Mongo for this project as the data I am working with is already presented in this form (the JSON) and, due to that, it seemed like a good opportunity to use and learn Mongo.
I am referring to the documentation on the Mongo site currently.
Thanks all
Try the following query:
db.warmod_events.find({ "match.id": 1, "match.event.player.name": 'Jim' })
which will match documents where the match id is the same as the embedded document player name.