I have a problem with a field name that has a period "." to it
I can only make it work if the field name is something like input_1 or input_1_2
But when it is something like input_1.2 it doesn't work.
function CalculateSig(stringToSign, privateKey){
//calculate the signature needed for authentication
var hash = CryptoJS.HmacSHA1(stringToSign, privateKey);
var base64 = hash.toString(CryptoJS.enc.Base64);
return encodeURIComponent(base64);
}
var d = new Date;
var expiration = 3600;
var unixtime = parseInt(d.getTime() / 1000);
var future_unixtime = unixtime + expiration;
var publicKey = "mupubkey";
var privateKey = "pyprikey";
var method = "POST";
var route = "forms/6/submissions";
stringToSign = publicKey + ":" + method + ":" + route + ":" + future_unixtime;
sig = CalculateSig(stringToSign, privateKey);
var url = 'https://www.localhostlbahblah.com/gravityformsapi/' + route + '?api_key=' + publicKey + '&signature=' + sig + '&expires=' + future_unixtime;
var values = {input_values:{'input_1.3':"test",// not working first name value
"input_2":"testetest", // this is working
}}
values_json = JSON.stringify(values);
$.post(url, values_json, function(data){
console.log(data.response);
});
Related
I'm trying to follow Microsoft's guide to generate a SAS Token, and here's my script:
function createSharedAccessToken(uri, saName, saKey) {
uri = // '...'
saName = // '...'
saKey = // '...'
if (!uri || !saName || !saKey) {
throw "Missing required parameter";
}
var encoded = encodeURIComponent(uri);
var now = new Date();
var week = 60 * 60 * 24 * 7;
var ttl = Math.round(now.getTime() / 1000) + week;
var signature = encoded + '\n' + ttl;
var signatureUTF8 = utf8.encode(signature);
var hash = crypto.createHmac('sha256', saKey).update(signatureUTF8).digest('base64');
return 'SharedAccessSignature sr=' + encoded + '&sig=' +
encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + saName;
}
createSharedAccessToken()
But I'm getting a:
var signatureUTF8 = utf8.encode(signature);
^
ReferenceError: utf8 is not defined
Any idea on why that is happening?
I am trying to print the log for following JavaScript. However, script is not printing the log value. I highlighted the variable value the script should identify in the if/else code, however after else it is not reading the $systemDate from outside the if/else statement; as a result it is not logging the value for $dueDate. I am trying following code:
_wait(_div("/date-display .* bwc-selected/"));
var $date = _getText(_div("/date-display .* bwc-selected/"));
_wait(2000);
_log($date);
_wait(2000);
var str = ($date)
var d = new Date(str)
var $systemDate = (d.getUTCMonth()+1) +"/"+ d.getUTCDate() + "/" + d.getUTCFullYear();
_log('System Date is:' + $systemDate);
var $dueDate = person.$dueDate;
if ($dueDate != null)
{
var $dueDate = person.$dueDate;
person.$dueDate = $dueDate;
_log('Due Date is:' + $dueDate);
}
else
{
var $days = 90;
var $theDate = new Date($systemDate);
var $pregnancyDueDate = new Date($theDate);
$pregnancyDueDate.setDate($pregnancyDueDate.getDate() + $days);
var due = ($pregnancyDueDate);
var n = new Date(due);
var $dueDate = (n.getUTCMonth()+1) +"/"+ n.getUTCDate() + "/" + n.getUTCFullYear();
_log('Due Date is:' + $dueDate);
person.$dueDate = $dueDate;
}
Do not redeclare your variable !
remove var from
var $dueDate = (n.getUTCMonth()+1) +"/"+ n.getUTCDate() + "/" + n.getUTCFullYear();
it should be:
$dueDate = (n.getUTCMonth()+1) +"/"+ n.getUTCDate() + "/" + n.getUTCFullYear();
You variable was already declared here before your if
var $dueDate = person.$dueDate;
and finally update your if condition to :
if ($dueDate != "")
because your cells can be just empty and not containing null values
i need to upload file to google cloud storage using signed url. i need to upload by diffrent steps.
Create a signedUrl using bucketName, service key and needed security credentials.(using any node.js library)
upload a single file with created signed url using a Postman or restClient.
This is my code for creating signedUrl for uploading
var crypto = require("crypto");
var fs = require("fs");
var URL_VALID_DURATION = 1000 * 120;//for 120 seconds
var expiry = Math.floor(((new Date).getTime() + URL_VALID_DURATION) / 1000);
var key = 'filename';
var bucketName = 'bucketName';
var accessId = 'gserviceaccount.com';
var stringPolicy = "POST\n" + "\n" + "\n" + expiry + "\n" + '/' + bucketName + '/' + key;
var base64Policy = Buffer(stringPolicy, "utf-8").toString("base64");
var privateKey = fs.readFileSync("google-services-private-key.pem", "utf8");
var signature = encodeURIComponent(crypto.createSign('sha256').update(stringPolicy).sign(privateKey, "base64"));
var signedUrl = "https://" + bucketName + ".commondatastorage.googleapis.com/" + key + "?GoogleAccessId=" + accessId + "&Expires=" + expiry + "&Signature=" + signature;
console.log(signedUrl);
But i got error, when using with postman or rest client
<?xml version='1.0' encoding='UTF-8'?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message>
<StringToSign>PUT
multipart/form-data
1458024549
/bucketName/fileName</StringToSign>
</Error>
Just changed stringPolicy method to PUT. and also send image as binary.
var crypto = require("crypto");
var fs = require("fs");
var URL_VALID_DURATION = 1000 * 120;//for 120 seconds
var expiry = Math.floor(((new Date).getTime() + URL_VALID_DURATION) / 1000);
var key = 'filename';
var bucketName = 'bucketName';
var accessId = 'gserviceaccount.com';
var stringPolicy = "PUT\n" + "\n" + "\n" + expiry + "\n" + '/' + bucketName + '/' + key;
var base64Policy = Buffer(stringPolicy, "utf-8").toString("base64");
var privateKey = fs.readFileSync("google-services-private-key.pem", "utf8");
var signature = encodeURIComponent(crypto.createSign('sha256').update(stringPolicy).sign(privateKey, "base64"));
var signedUrl = "https://" + bucketName + ".commondatastorage.googleapis.com/" + key + "?GoogleAccessId=" + accessId + "&Expires=" + expiry + "&Signature=" + signature;
console.log(signedUrl);
Today is my first day using Google Apps Script. I am trying to make a script to grab weather information from the Wunderground Api and paste it into a spreadsheet.
For some reason I am getting the error message "Missing ';' before statement. (Line 34)".
I've searched for a solution but cant find why I am getting this error in my code.
//Everyday this script gets weather data from Weather Underground and records it in this spreadsheet.
cDay = 0, cTemp = 1, cHumidity = 2, cPressure=3, cSparkline=4, cConditions=5;
nCols=7;
function getTemp() {
var url = 'http://api.wunderground.com/api/' + appKey + '/conditions/q/CO/Aspen.json';
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var response = UrlFetchApp.fetch(url);
var contentText = response.getContentText();
var conditions = Utilities.jsonParse(contentText);
var todaysConditions = conditions;
var temp = todaysConditions.current_observation.temp_c;
var humidity = todaysConditions.current_observation.relative_humidity;
var pressure = todaysConditions.current_observation.pressure_in;
var conditions = todaysConditions.response.features.conditions;
sheet.insertRowAfter(1);
var range = sheet.getRange(2,1,1, nCols);
var row = range.getValues()[0];
var d = new Date;
var month = d.getMonth() + 1;
var day = d.getDate();
var year = d.getFullYear();
var hour = d.getHours() + 1;
var minutes = d.getMinutes();
row[cDay] = month + '/' + day + '/' + year + '' + hour + ':' minutes; //here is the error
row[cTemp] = temp;
row[cHumidity] = humidity;
row[cPressure] = pressure;
row[cConditions] = conditions;
var nRows = numRows >= 10 ? 10 : numRows;
//row[cSparkline] = "=SPARKLINE(R[0]C[-3]:R[" + (nRows-1) + "]C[-3])";
range.setValues([row]);
}
Any help is appreciated
You have missed the '+' sign
row[cDay] = month + '/' + day + '/' + year + '' + hour + ':' + minutes;
I am trying to POST JSOn data to a cloud with this function in function node.
var accx = 15;
var accy = 45;
var accz = 12;
//JSON FORMING BY JAVASCRIPT OBJECT
var output = [];
output[0] = {
name: "Accel_X",
value: accx.toString(), // retrieve x
};
output[1] = {
name: "Accel_Y",
value: accy.toString(), // retrieve y
};
output[2] = {
name: "Accel_Z",
value: accz.toString() // retrieve z
};
var record = [];
record[0] = {
starttime: formatDate(new Date()),
output: output,
};
var observations = [];
observations[0] = {
sensor: "C2105",
record: record,
};
var fromData = {};
fromData.version = "1.0.1";
fromData.observations = observations;
//MONTH NAME FUNCTION
function show_now(){
var my_month=new Date()
var month_name=new Array(12);
month_name[0]="JAN"
month_name[1]="FEB"
month_name[2]="MAR"
month_name[3]="APR"
month_name[4]="MAY"
month_name[5]="JUN"
month_name[6]="JUL"
month_name[7]="AUG"
month_name[8]="SEP"
month_name[9]="OCT"
month_name[10]="NOV"
month_name[11]="DEC"
return month_name[my_month.getMonth()];
}
//RETURN DATE AT FORMATTED WAY THAT IS ACCEPTED BY CLOUD
function formatDate(d) {
return d.getDate() + '-' + (show_now()) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + " IST";
}
var fromDatan = JSON.stringify(fromData);
//alert(fromDatan);
//POST JSON SENSOR DATA
fromDatan.headers = {
"x-api-key": "ucrFr234r23rrxfAIH2L4=",
"content-type": "application/json;charset=UTF-8"
}
return fromDatan;
I have given correct url in url node but it is returning no response and I am not seing any data is being post
Anyone please worked with node-red.js please help.
Your function node needs to return an object with a payload property containing the data you want to send in the http request. It is also not necessary to stringify the object as the http request node will do that for you.
var fromDatan = {};
fromDatan.payload = fromData;
fromDatan.headers = ...
return fromDatan