Sending data from Google Scripts to Influx "missing tag value"

Hello,

Shot in the dark but I wonder if anyone can help.

I’m trying to figure out how to send json data from Google Scripts to Influx and am using the following code:

function testPost() {

var response;

var tags = {
testname:‘j’
}

var fields = {
value:1
}

var data = {‘measurement’:‘cpu_load_short’,‘tags’:tags,‘time’:0,‘fields’:fields};

Logger.log(JSON.stringify(data));

var options = {
‘method’ : ‘post’,
‘muteHttpExceptions’ : true,
‘contentType’: ‘application/json’,
‘payload’ : JSON.stringify(data)

};
/*
options = {
‘method’ : ‘post’,
‘contentType’: ‘text/plain’,
‘payload’ : ‘mymeas,mytag=blob myfield=90 1463683075000000000’
}*/

try {

response = UrlFetchApp.fetch('http://w.x.y.z:8086/write?db=mydb&u=***&p=***', options);
Logger.log(response.getContentText());

}

catch(err) {

Logger.log(err);

}

}

This is what I capture from the google script:

[19-09-05 13:52:39:586 BST] {“measurement”:“cpu_load_short”,“tags”:{“testname”:“j”},“time”:0,“fields”:{“value”:1}}
[19-09-05 13:52:39:698 BST] {“error”:“unable to parse ‘{“measurement”:“cpu_load_short”,“tags”:{“testname”:“j”},“time”:0,“fields”:{“value”:1}}’: missing tag value”}

I suspect the issue is somewhere with the JSON.stringify but not entirely sure why. The error seems to indicate missing tag data despite it being provided.

Generally, it gives an error like that when the line protocol isn’t quite right and it gets confused about the formatting. I too, suspect something is happening with the stringify. I’m trying to recreate it now.

Helo Aund where you able to resolve this issue? I have a requirement where i need to read the data from the google sheet using google app script and send it to the Inflxudb using the HTTP API. i only see Bad Request error. Any thought? Please help!

Hello @sgdevl,
Where is the Bad Request error coming from? Can you print and share your resulting line protocol please?

Hello @Anaisdg , thanks for your response. Please find the code below which i need to trigger from the Google App Script.

function dataentry() {

var response;

var tags = {
"PROGRAM":"Migration"
}

var fields = {
"TESTED_BY": "Peter",
"RESULT":1,
"STATUS":"Fail"
}

var data = {"measurement":"testing","tags":tags,"time":,"fields":fields};

Logger.log(JSON.stringify(data));

var options = {
"method" : "post",
"muteHttpExceptions" : true,
"contentType": "application/json",
"payload" : JSON.stringify(data)
//"payload" : data
};

try {
response = UrlFetchApp.fetch('http://xx.xx.xx.xx:8086/write?db=mydbb', options);
Logger.log(response.getContentText());
}

catch(err) {
Logger.log(err);
}
}

My InfluxDB is running in a different server, so I have used the IP address. The below command works perfectly fine and it sends the data to the influxdb but when it try to do it via Google App script, i get the error message - Exception: Bad request: http://xx.xx.xx.xx:8086/write?db=mydbb

Curl command used and working - curl -i -XPOST http://192.168.0.105:8086/write?db=mydbb --data-binary "testing,PROGRAM=Migration TESTED_BY=\"Peter\",STATUS=\"Fail\",RESULT=1"

Appreciate your help. Thanks!

this is the simple google app script that I’m trying to run to insert data to influxdb. The syntax is also taken from postman where it’s working. Even this fails with error - Exception: Bad request: http://192.xx.xx.xx:8086/write?db=mydbb

function preshfinder() {

var url = "http://192.xx.xx.xx:8086/write?db=mydbb";

var raw = 'cpu_load_short,host=server01,region=us-345345 value=0.34564 3453450';

var myheaders = {"Content-Type" : "text/plain"};

var options = {

  method: 'POST',

  headers: myheaders,

  body: raw,

  redirect: 'follow'

};

var response = UrlFetchApp.fetch(url, options);

Logger.log(response.getContentText());

}

Hello @sgdev,
Your timestamp looks suspicious to me. It should be in ns precision.

What version of InfluxDB are you using?

This might be useful to you as well:

I was able to insert the data with that timestamp too (using curl), but i did try with ns as well and still ran into the same error.
I’m using influxdb-1.8.3-1 version.