API Veeml to export data - database

I need to load data from Veeml into our SAP database.
We already scheduled some loading processes and I wonder if there is a way to query Veeml to transfer data in SAP.

You can use the API /getgrid2 to retrieve data from VEEML in a JSON format.
type: "POST",
url: « //the-url.ofyour.portal/getgrid2",
data: { "jsonstring": JSON.stringify(_jsonstring) },
success: function (data) {
console.log(data);
}
With _jsonstring as :
{
"Token": , -> authentication token
"DataView":"", -> name of the datatable
"Universe":{"column1":"''value1'"},
-> List of restriction if need (current universe)
"Chart":{
"Type":"grid",
"treillis":"",
"Dimension1":["column1 as column1"],
-> List of dimensions
"Dimension2":[],
"Fact":["AVG(Value) as Value"],
-> List of metrics
"LineorColumn":"Lines"
}
Use this endpoint to export data from VEEML.
You will get JSON that you can use in your application.
type: "POST",
data: { "jsontring": jsonstring, "DashboardId": _DashboardId},
url: "//the-url.ofyour.portal/getgrid2",
contentType: "application/json",
success: function (data) {
window.open('//xxx.datatelling.eu/nextractorcsvlink/' + data.uid, '_blank' );
}
Below is a full instance with the authentication to get the turnover by week for the year 2021 :
var _email = 'john.doe#yourcompany.com';
var _password = 'bigfan';
var _hash = CryptoJS.SHA256(_password);
var _data = {"email": _email, "password": _hash.toString()};
var _url = "https://the-url.ofyour.portal/login";
$.ajax({
type: "POST",
url: _url,
dataType : 'jsonp',
data: _data,
error: function(xhr, response, error)
{
console.log(error);
},
success: function(json)
{
console.log(json.success);
_url = "http://the-url.ofyour.portal/getgrid2";
// _jsontring is the request to pass to the API
_jsontring = {"Token": json.success,"DataView":"yourentrypointdb.dbo.
[your_dataview]","Universe":
{"Year":"'2021'"},"Chart":{"Type":"grid","treillis":"","Dimension1":["Week as Week"],
"Dimension2":[],"Fact":["SUM(Amount) as Turnover"],
"LineorColumn":"Lines"}};
_data = {"jsontring": JSON.stringify(_jsontring)};
$.ajax({
type: "POST",
url: _url,
dataType : 'jsonp',
data: _data,
error: function(xhr, response, error)
{
console.log('error');
console.log(error);
},
success: function(json)
{
console.log(json);
$("#result").html(json);
}
});
}
});

Related

AngularJS http POST take lot of time to load data

i have a problem in loading data take from 1 to 30 seconds to load 10000 GPS coordinates ,
after checking the server side i see server take 300ms of traitement between database query and do some traitement and send response to AngularJS side
var getItineraryVehicule_n=function (id_v,date_s,date_e) {
return $q(function (resolve,reject) {
var LOCAL_TOKEN_KEY = 'yourTokenKey';
var token= window.localStorage.getItem(LOCAL_TOKEN_KEY);
token=JSON.parse(token.split('#')[0]);
$httpBackend.whenPOST(/.*/).passThrough();
$http({
method: 'post',
dataType: 'json',
url: SERVER.url+token.response.response.user.id+'/itinerary_mongodb',
header: {
'Content-Type': 'application/json'
},
data: {
"date_s": date_s ,
"date_e": date_e,
"id_v":id_v
}
}).success(function (result) {
//console.log(JSON.stringify(result));
resolve(result);
}).error(function (err) {
console.log(err);
reject('error itinerary vehicule');
});
});
}
i have just doing that but after several times of testing I see that time in the network tab is the same in the console.log time
var getItineraryVehicule_n=function (id_v,date_s,date_e) {
var d = new Date();
return $q(function (resolve,reject) {
var LOCAL_TOKEN_KEY = 'yourTokenKey';
var token= window.localStorage.getItem(LOCAL_TOKEN_KEY);
token=JSON.parse(token.split('#')[0]);
$httpBackend.whenPOST(/.*/).passThrough();
$http({
method: 'post',
dataType: 'json',
url: SERVER.url+token.response.response.user.id+'/itinerary_mongodb',
header: {
'Content-Type': 'application/json'
},
data: {
"date_s": date_s ,
"date_e": date_e,
"id_v":id_v
}
}).success(function (result) {
console.log("in the service is take : "+(new Date().getTime()-d.getTime()));
resolve(result);
}).error(function (err) {
console.log(err);
reject('error itinerary vehicule');
});
});
}

Passing $scope through AJAX, but only few variables inserted

I am trying to pass a variable through AJAX to an API. Here is the angular controller:
$scope.register = function() {
_.each($scope.photos, function(images) {
$upload.upload({
url: '/api/indorelawan/timaksibaik/register/upload-images',
method: 'POST',
data: {},
file: images
})
.success(function(data) {
$scope.team.photos.push(data.result.path);
})
});
$http({
method : 'POST',
url : '/api/indorelawan/timaksibaik/register',
data : $.param($scope.team),
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.success(function(data) {
if (!data.success) {
...
}
else {
...
}
});
}
I tried console.log the $scope.team.photos before it calls the /register API. It displays the data perfectly. But when /register API is runned, the $scope.team.photos is not included. Here is the API:
/*Register Tim Aksi Baik*/
apiRouter.post('/timaksibaik/register', function(req, res) {
// TODO: Create new value to access general statistics data, e.g.: response time.
console.log(req.body);
var team = new GoodActionTeam();
_.each(req.body, function(v, k) {
team[k] = v;
});
team.created = new Date();
team.save(function(err, data) {
if (err) {
res.status(500).json({
success: false,
message: "Gagal menyimpan data organisasi baru.",
system_error: "Error while saving organization data: " + err.message
});
}
else {
res.status(200).json({
success: true,
message: "Organisasi Berhasil Dibuat",
result: data
});
}
});
});
The output of the req.body is only:
{ logo: '/uploads/user_avatar/register/2018-1-14_18:18:3.png',
name: 'ererr',
url_string: 'ererr',
description: 'dfdfd',
focuses: [ '549789127e6a6e2c691a1fc0', '549789127e6a6e2c691a1fc0' ] }
It looks like the $scope.team.photos is not included when the data is passed to the API. What went wrong?
The $upload.upload() is async and by the time you make a post with $scope.team there is no guarantee that all the upload success callbacks have been completed

Angularjs http post request - params are not reaching to server

I am trying to create post request with angularjs. This is my code for adding an supplier to server.
SupplierService.addNewSupplier = function(supplier) {
alert (supplier.name);
alert (supplier.mobile);
var Indata = {'name': supplier.name, 'mobile': supplier.mobile};
//var Indata = {'product': $scope.product, 'product2': $scope.product2 };
var req = {
url: SupplierURL,
method: 'POST',
params: Indata,
headers: {'Content-Type': 'application/json'}
};
//$http.post(SupplierURL, Indata)
$http(req)
.then(function(success){
console.log(success);
//SupplierList.push({id: data, name: supplier.name, mobile: supplier.mobile});
supplier.name = "";
supplier.mobile = "";
},function (error){
console.log(error);
alert ('Supplier add error.');
});
};
After making the request, callback is coming to error part and in console log i can see.
{error: true, message: "Failed to create supplier. Please try again", name: null, mobile: null}
Why name and mobile is not reaching to server. Same request works fine with postman(api testing tool). So i don't thing there can be anu issue in server side code. Any help will be appreciated.
From the $http documentation you can clearly see request parameters:
https://docs.angularjs.org/api/ng/service/$http
var req = {
method: 'POST',
url: 'http://example.com',
headers: {
'Content-Type': undefined
},
data: { test: 'test' }
}
$http(req).then(function(){...}, function(){...});
So, in your case you need to switch params with data:
var req = {
url: SupplierURL,
method: 'POST',
data: Indata,
headers: {'Content-Type': 'application/json'}
};

Accessing API with $http POST Content-Type application/x-www-form-urlencoded always gets 'false' results

I have the following REST Service which I have to access on POST Method,
I can access it via jQuery but I don't know how to do it with AngularJS (v1)
<string xmlns = "http://schemas.microsoft.com/2003/10/Serialization/">
<script id = "tinyhippos-injected" />
{
"volumeResult": {
"gyydt": "9771241.17704773",
"gytotal": "29864436.1770477",
"gybudgeted": "29864436.1770477",
"lyydt": "10197350",
"lytotal": "27859381",
"lybudgeted": "10197350",
"cyytd": "6992208",
"lastUpdate": "March-2017"
},
"valueResult": {
"gyydt": "26862094",
"gytotal": "68217952",
"gybudgeted": "68232952",
"lyydt": "0",
"lytotal": "0",
"lybudgeted": "0",
"cyytd": "68217952",
"lastUpdate": "March-2017"
},
"trucksResult": {
"gyydt": "165951",
"gytotal": "497879",
"gybudgeted": "497879",
"lyydt": "168822",
"lytotal": "468814",
"lybudgeted": "168822",
"cyytd": "119442",
"lastUpdate": "March-2017"
}
}
</string>
Here is my controller.js:
angular.module('starter.controllers', [])
.controller('DashCtrl', ['$scope', '$http', function ($scope, $http) {
$http({
//headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'},
headers: {'Content-Type' : 'application/json'},
url: 'https://myurl../api/getHPData',
method: 'POST',
// data: data,
params: {
"stationId": 263,
"crusherId": 27,
"monthYear": '2016-04'
}
})
.then(function (response) {
console.log(response);
})
// I don't have to use .success and .error function as they are [depricated][2]
//.success(function (data, status, headers, config) {
// $scope.greeting = data;
// var Result = JSON.stringify(data);
// var Result = JSON.parse(data);
//})
//.error(function (error, status, headers, config) {
// console.log("====================== Error Status is: " + error);
// console.log("====================== Status is: " + status);
// console.log("====================== Error occured");
//})
}]) // eof controller DashCtrl
.controller('MapsCtrl', function($scope) {})
.controller('AccountCtrl', function($scope) {
$scope.settings = {
enableFriends: true
};
});
What I want is value of:
"volumeResult" > "gytotal"
Problems:
It always return:
Object {data: "{"result":"false"}", status: 200, config: Object, statusText: "OK", headers: function}
and
When I pass monthYear without quotes it process (arithmetic) it as (2016-04 = 2012)
As the service is POST but when I analyze it in Chrome Developers Tool so I get: (Query String, which isn't meant to be POST)
ionic.bundle.js:25005
XHR finished loading: POST
"https://myurl../api/getHPData?crusherId=27&monthYear=2016-4&stationId=263"
Possible solutions:
Either I am using wrong header:
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Accept': 'application/json'
},
Or header may be,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
Or as per my friend says:
When I change your code to use the code above, I get this error:
"{"Message":"The requested resource does not support http method
'OPTIONS'."}" Which means that there is a CORS (Cross-origin Resource Sharing) issue. Chrome is trying to make a "preflight" request to allow
CORS, but the server doesn't know what to do with it.
But I don't think it is because of this as I am receiving:
Object {data: "{"result":"false"}", status: 200, config: Object,
statusText: "OK", headers: function}
from server. Noted that: {"result":"false"} is the message displayed by the server when it didn't find data or you pass wrong parametes. Also bellow jQuery code is proof that I can access the server. :)
Edit
jQuery Snippet:
<script>
$(document).ready(function() {
get_homepage_data(263, 27, '2016-04');
function get_homepage_data(stationIds, crusherIds, date) {
var url = "https://myurl..";
var data_to_send = {
'stationId': stationIds,
'crusherId': crusherIds,
'monthYear': date
};
console.log("Value is: " + JSON.stringify(data_to_send));
//change sender name with account holder name
// console.log(data_to_send)
$.ajax({
url: url,
method: 'post',
dataType: 'json',
//contentType: 'application/json',
data: data_to_send,
processData: true,
// crossDomain: true,
beforeSend: function () {
}
, complete: function () {}
, success: function (result1) {
// I know I can do it in one line but lazy enough to edit it here :p
var Result = JSON.parse(result1);
var value_data = Result["valueResult"];
var foo = value_data["gyydt"];
console.log("Log of foo is: " + foo);
var foo2 = 0;
// 10 lac is one million.
foo2 = foo / 1000000 + ' million';
console.log(JSON.stringify(value_data["gyydt"]) + " in million is: " + foo2);
}
, error: function (request, error) {
return false;
}
});
}
}); // eof Document. Ready
</script>
Output of above script is script is:
Value is: {"stationId":263,"crusherId":27,"monthYear":"2016-04"}
XHR finished loading: POST "https://myurl../api/getHPData".
Log of foo is: 26862094
"26862094" in million is: 26.862094 million
Which is indeed perfect. :)
try to use $http this way ..
$http.post("https://myurl../..",JSON.stringify({
stationId: 263,
crusherId: 27,
monthYear:'2016-04'
})).then(function(res){
console.log(res);
}).catch(function(errors){
console.log(errors);
})
I got answer. Whao.
Thank you georgeawg for his answer:
He says:
When posting form data that is URL encoded, transform the request with the $httpParamSerializer service:
$http({
headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'},
url: 'https://myurl..',
method: 'POST',
transformRequest: $httpParamSerializer,
transformResponse: function (x) {
return angular.fromJson(angular.fromJson(x));
},
data: {
"stationId": 263,
"crusherId": 27,
"monthYear": '2016-04'
}
})
.then(function(response) {
console.log(response);
$scope.res = response.data;
console.log($scope.res);
});
Normally the $http service automatically parses the results from a JSON encoded object but this API is returning a string that has been doubly serialized from an object. The transformResponse function fixes that problem.
Now I am able to get value of gytotal as:
var myData = parseFloat(response.data.valueResult.gytotal);
console.log(myData);

ngResource not returning data in json object format

I have setup a basic angular and node application. The node server is returning response in JSON format :
[{"FeedId":"56aa6aece3d7031b044b34de","Name":"geeksforgeeks","FeedUrl":"http://www.geeksforgeeks.org/feed/?paged=INDEX","FeedItems":[]}]
Node method :
router.get('/feeds', function(req, res, next) {
request.get(webApiUrl + '/api/Feed', { headers: {
'Content-Type': 'application/json'
}}, function(error, response, body)
{
if(error) {
return next(error);
}
res.json(body);
});
});
On angular side, I am using ngResource and I have defined the configuration as:
this.$resource("http://localhost:3000/feeds/:feedName", {},
{
transformResponse: function(data, headers) {
return angular.fromJson(data);
},
post: {method:'POST'},
get : {method: 'GET'},
query: {method: 'GET', isArray: false },
update: {method: 'PUT', isArray: false},
'delete': {method:'DELETE', params: { feedName:"#feedName" }}
});
Problem I am facing is that the ngResource is not returning result in json object format instead its converting the response in array of characters.
var resource = this.dataAccessService.getFeedResource();
this.feeds = [];
let _me = this;
resource.get((data) => {
console.log(data); **//array of characters**
angular.forEach(data, function(ff) {
console.log(ff.Name);**//undefined**
});
});
How can I make ngResource to return data in json object format similar to what node server is returning?

Resources