Attempting to return a list of all transactions on my Square account for a given location, however, when I run my code I get back an empty JSON object from the Transactions API. Looking for a correct example of how to pull a list of all transactions and read/save them with Transactions API in javascript.
Here's my code:
var SquareConnect = require('square-connect');
var defaultClient = SquareConnect.ApiClient.instance;
var oauth2 = defaultClient.authentications.oauth2;
oauth2.accessToken = "ACCESS-TOKEN";
var TransactionsApi = new SquareConnect.TransactionsApi();
var listTransactions = TransactionsApi.listTransactions(locationId);
console.log(JSON.stringify(listTransactions));
The return is simply:
>>> {}
Related
i am new to google earth engine.
I have a program for Atmosphere Monitoring.
I have managed to pull data for historical data. However , i can't pull recent data e.g. (a couple of days, today , yesterday etc.) , i get ' memory limit exceeded.' or (Collection.toList: The value of 'count' must be positive. Got: 0.)
As it says 'Near-Real-Time' that mean that the data must update many times a day? My final goal is to be able to pull data in (near) real time so that I can this data through some other program visualize it. Is that possible?
Any advice will be helpful!
Thanks in advance!
var pt = ee.Geometry.Point(23.72801716860135,37.984115295446216);
Map.centerObject(pt,14);
Map.addLayer(pt);
var starDate = '2023-02-09';
var endDate = '2023-02-10';
var data = ee.ImageCollection('ECMWF/CAMS/NRT').select('total_aerosol_optical_depth_at_550nm_surface')
.filterDate(starDate, endDate);
print(data);
var allDates = ee.List(data.aggregate_array('system:time_start'));
var allDatesSimple = allDates.map(function(date){
return ee.Date(date).format().slice(0,10);
});
//print(allDatesSimple);
var getTemp = function(image) {
// Reducing region and getting value
var value_tmmx = ee.Image(image)
.reduceRegion(ee.Reducer.first(), pt)
.get('total_aerosol_optical_depth_at_550nm_surface');
return ee.Number(value_tmmx).multiply(0.1);
};
var count = data.size();
var tmmx_list = data.toList(count).map(getTemp);
print("tmmn_list", tmmx_list);
var paired = allDatesSimple.zip(tmmx_list);
print ("paired", paired);
var myFeatures = ee.FeatureCollection(paired.map(function(el){
el = ee.List(el); // cast every element of the list
return ee.Feature(null, {
'date': ee.String(el.get(0)),
'aerosol':ee.Number(el.get(1)),
});
}));
print(myFeatures);
// Export features, specifying corresponding names.
Export.table.toDrive(myFeatures,
"export_aerosol", //my task
"GEE_Folder", //my export folder
"aerosol2", //file name
"CSV");
I have been stumped on this for a while. I am fairly new to Google script app and wanted to see if there is a way to make this happen. So far, I've used a few methods within Google Sheet but seem to not get it working.
The code below does give me an output of all the data, however, the data that is nested in the data.custom_fields[x] has multiple objects that is separated by ",". I would like to be able to filter out the other key words and just use whatever is inside "display_value=". The display_value= is not always in the same area so have to run a search for them.
I am assuming some kind of If statement would be used here..
An example of the object is:
{type=x, resource_subtype=x, created_by={name=x, gid=x, resource_type=x}, display_value=Cool Value, description=x, enabled=x, resource_type=custom_field, gid=x, enum_options=[x.lang.Object;x, enum_value={x}, name=x}
I've tried to split function as well but not sure how to filter out the words I need.
function Users() {
var options = {
"headers" : {
"Authorization": "API Key here"
}
}
var response = UrlFetchApp.fetch("URL here", options);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheet = ss.getSheetByName("Tab Name here"); // specific sheet name getSheetByName(""); alternatively use ss.getActiveSheet()
var dataAll = JSON.parse(response.getContentText()); //
var dataSet = dataAll.data; // "data" is the key containing the relevant objects
var rows = [],
data;
for (i = 0; i < dataSet.length; i++) {
data = dataSet[i];
rows.push([
data.gid,
data.name,
data.permalink_url,
data.due_on,
data.custom_fields[1],
data.custom_fields[2],
data.custom_fields[4],
data.custom_fields[5],
data.custom_fields[6],
data.custom_fields[7],
data.custom_fields[8],
data.custom_fields[9],
]); //your JSON entities here
}
// [row to start on], [column to start on], [number of rows], [number of entities]
dataRange = sheet.getRange(2, 1, rows.length, 12);
dataRange.setValues(rows);
Thank you in advance!
Example Image of JSON imported data
Although they appear separated by ,'s, that is only how they're displayed in the log. Because you're using JSON.parse, you're receiving/converting to an Object, not a string.
Because data.custom_fields is an array of objects, you can access the property/key values as : data.custom_fields[x].display_value.
Learn More:
JSON.parse()
Accessing Object Properties
If you want to extract display_value, try
let myVal = myData.match(/(?<=display_value=)[^,]+/g)[0]
I guess that myData could be data.custom_fields[5], so replace it by
data.custom_fields[5].match(/(?<=display_value=)[^,]+/g)[0]
I am self taught with Apps Script, so generally approach one problem at a time, as it comes up. Arrays are confusing!
I am using an API to get the number of social followers for Facebook, Twitter and Instagram accounts. Here is the code so far. Note I have removed the API call specifics for privacy, I have also used fake profile ID's in the above, for example 1111 = Facebook, 2222 = Twitter, etc...
var response = UrlFetchApp.fetch(endpointUrl, params);
var jsonss = JSON.parse(response.getContentText());
var dataset = jsonss.data;
Logger.log(dataset);
[{dimensions={customer_profile_id=1111, reporting_period.by(day)=2021-10-31}, metrics={lifetime_snapshot.followers_count=407919.0}}, {dimensions={reporting_period.by(day)=2021-10-31, customer_profile_id=2222}, metrics={lifetime_snapshot.followers_count=1037310.0}}, {dimensions={reporting_period.by(day)=2021-10-31, customer_profile_id=3333}, metrics={lifetime_snapshot.followers_count=806522.0}}]
then map the array -
var followers = dataset.map(function(ex){return [ex.dimensions,ex.metrics]});
Logger.log(followers);
[[{reporting_period.by(day)=2021-10-31, customer_profile_id=1111}, {lifetime_snapshot.followers_count=407919.0}], [{reporting_period.by(day)=2021-10-31, customer_profile_id=2222}, {lifetime_snapshot.followers_count=1037310.0}], [{customer_profile_id=3333, reporting_period.by(day)=2021-10-31}, {lifetime_snapshot.followers_count=806522.0}]]
Now I get stuck, I am not sure how to get 'followers_count' when 'profile_id=1111', can someone please help? I have tried using another map function ( var followers = dataset.map(function(ex){return [ex.dimensions.map(function(ex2){return [ex2.followers_count]}]}); ) however this doesn't work...
Any suggestions to push me in the right direction is very much appreciated!
If Logger.log(followers); is [[{reporting_period.by(day)=2021-10-31, customer_profile_id=1111}, {lifetime_snapshot.followers_count=407919.0}], [{reporting_period.by(day)=2021-10-31, customer_profile_id=2222}, {lifetime_snapshot.followers_count=1037310.0}], [{customer_profile_id=3333, reporting_period.by(day)=2021-10-31}, {lifetime_snapshot.followers_count=806522.0}]] and you want to retrieve the value of lifetime_snapshot.followers_count: 407919 by using customer_profile_id: 1111, how about the following sample script?
Sample script:
In this sample script, your values of followers is used.
const profile_id = 1111; // Please set customer_profile_id you want to use.
const res = followers.reduce((ar, [a, b]) => {
if (a["customer_profile_id"] == profile_id) {
ar.push(b["lifetime_snapshot.followers_count"]);
}
return ar;
}, []);
if (res.length == 0) return;
const followers_count = res[0];
console.log(followers_count);
When this script is used for your values of followers, I thought that 407919 is retrieved.
If the same IDs are existing, you can retrieve them using console.log(res).
Reference:
reduce()
I have cookie data printed in console now i want to create object that will get data from cookie firstname ,lastname,eamil and id. How i can create object when i recieve data in below format ?
mainCtrl.js
angular.module('angularModelerApp')
.controller('AccessCtrl',['$scope', '$cookies','UserAccessFactory',
function ($scope, $cookies,UserAccessFactory) {
$scope.newUser = {};
$scope.patternAttuid = new RegExp("^[a-z]{2}[0-9]{3}[a-z0-9]$");
$scope.cookie = $cookies.get('attESHr');
console.log('newUser',$scope.cookie)
});
data printed $scope.cookie
newUser Mike|Pierro|mp529u#us.att.com|||sl3561||mp529u,RHCRSMK,SBGPQX9,4131585|NNNNNNNNNNNNNNYNNYNNNNNN|MIKE|EY1PE2600|
You can use split to get the values separated. You should know that doing this is not encouraged because if the format changes, your code will be broken. But if you really need to parse that string, you could try this:
var parts = $scope.cookie.split("|");
$scope.newUser.firstName = parts[0];
$scope.newUser.lastName = parts[1];
$scope.newUser.email = parts[2];
// ... etc with all the other values, keeping in mind the index
I have data being sent to a custom data list from the following code:
// Get the site name and dataLists
var site = siteService.getSite("Testing");
var dataLists = site.getContainer("dataLists");
// Check for data list existence
if (!dataLists) {
var dataLists = site.createNode("dataLists", "cm:folder");
var dataListProps = new Array(1);
dataListProps["st:componentId"] = "dataLists";
dataLists.addAspect("st:siteContainer", dataListProps);
dataLists.save();
}
// Create new data list variable
var orpList = dataLists.childByNamePath("orplist1");
// If the data list hasn't been created yet, create it
if (!orpList) {
var orpList = dataLists.createNode("orplist1","dl:dataList");
// Tells Alfresco share which type of items to create
orpList.properties["dl:dataListItemType"] = "orpdl:orpList";
orpList.save();
var orpListProps = [];
orpListProps["cm:title"] = "Opportunity Registrations: In Progress";
orpListProps["cm:description"] = "Opportunity registrations that are out for review.";
orpList.addAspect("cm:titled", orpListProps);
}
// Create new item in the data list and populate it
var opportunity = orpList.createNode(execution.getVariable("orpWorkflow_nodeName"), "orpdl:orpList");
opportunity.properties["orpdl:nodeName"] = orpWorkflow_nodeName;
opportunity.properties["orpdl:dateSubmitted"] = Date().toString();
opportunity.properties["orpdl:submissionStatus"] = "Requires Revisions";
opportunity.save();
This correctly creates data list items, however, at other steps of the workflow require these items to be updated. I have thought of the following options:
Remove the data list item and add another with the updated information
Simply update the data list item
Unfortunately I have not found adequate solutions elsewhere to either of these options. I attempted to use orpWorkflow_nodeName, which is a unique identifier generated at another step, to identify a node to find it. This does not seem to work. I am also aware that nodes have unique identifiers generated by Alfresco itself, but documentation doesn't give adequate information on how to obtain and use this.
My question:
Instead of var opportunity = orpList.createNode(), what must I use in
place of createNode() to identify an existing node so I can update its
properties?
You can use this to check existing datalist item.
var opportunity = orpList .childByNamePath(execution.getVariable("orpWorkflow_nodeName"));
// If the data list Item is not been created yet, create it
if (!opportunity ) {
var orpList = orpList .createNode(execution.getVariable("orpWorkflow_nodeName"),"dl:dataList");}