Send Table Data via Ajax and Web Api - asp.net

I have tables with different column and row count as JSON on client side, e.g.:
[
["", "Kia", "Nissan", "Toyota", "Honda"],
["2008", "-5", "11", "12", "13"],
["2009", "20", "-11", "14", "13"],
["2010", "30", "15", "-12", "readOnly"]
]
I want to send this table to server via ajax and ASP.NET Web Api. What is the best way to do this?
I always get null as value when i want to post as text and receive it as [FromBody]string value. I can't use a class because of different table sizes?

the answer was in the ajax code. I didn't had the right data parameter. Right is:
$.ajax({
url: '../webapi/Products',
type: 'POST',
dataType: "text",
data: "="+JSON.stringify( data ),
success: function (test) {
alert(test);
},
error: function (test) {
alert("Error");
}
then i can use e.g. JArray from JSON.NET to parse the value string.

Related

Writing data to google sheets using Google Sheets API with R

I try to write a data frame to google sheets using R. I've successfully added data frame example from google for developers API reference method selector but got Error 404 when tried to do so from my R script.
I've successfully got API credentials by token <- gargle::token_fetch() with spreadsheet and drive scopes. I've inserted some blank lines in the beginning of my table:
sheet_ins_range <- jsonlite::fromJSON('{
"requests": [
{
"insertRange": {
"range": {
"startRowIndex": 2,
"endRowIndex": 2,
"sheetId": XXXXX
},
"shiftDimension": "ROWS"
}
}
]
}')
sheet_ins_range$requests$insertRange$range$endRowIndex <- 10
body <- jsonlite::toJSON(sheet_ins_range)
response <- POST("https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}:batchUpdate",
body = body, encode = "json", config(token = token))
# response: Status: 200
But when I try to write some data into this region I get Error Status: 404.
google_BU <- jsonlite::fromJSON('{
"data": [
{
"range": "Sheet1!A1:D4",
"values": [
["Item", "Cost", "Stocked", "Ship Date"],
["Wheel", "$20.50", "4", "3/1/2016"],
["Door", "$15", "2", "3/15/2016"],
["Engine", "$100", "1", "3/20/2016"]],
"majorDimension": "ROWS"
}
],
"valueInputOption": "USER_ENTERED"
}')
body <- jsonlite::toJSON(google_BU)
response <- POST("https://docs.google.com/spreadsheets/d/{spreadsheetId}/values:batchUpdate",
body = body, encode = "json", config(token = token))
# response: Status: 404
I suppose I do something wrong with HTTP request, because there is nothing wrong with this request body when I use googles "Try this method" page.

Hasura Remote Schema to Database Array relationship returns invalid input syntax for type integer

I have got a custom Graphql server running in a separate server and I wanted to include a query from it to Hasura with the remote schema feature. I've created the remote schema and it is working well but I also needed to create an array relationship between the response in the remote schema query to a table in Postgres.
Currently, It is returning an error below.
{ "errors": [ { "extensions": { "code": "data-exception", "path": "$" }, "message": "invalid input syntax for type integer: "["36", "37", "38", "39", "40", "41", "42", "43"]"" } ] }
What should be the response from the remote schema query to To get the related entries from the database with the list of ids returned from the remote schema query response?

Here Fleet Telematics CalculateRoute service not accessible using api key

I'm trying to use the Here Fleet Telematics CalculateRoute.json service, to calculate trip costs (toll, etc). The sample page uses api_id and api_key for authentication. In my (Freemium) account, I don't see a way where I can generate that.
What I did is copy the request the sample site makes, and replace the app_id and app_key parameters with apikey=**key**. I also removed the jsoncallback parameter.
I get the back following JSON:
{
"faultCode": "s14e781b4-b577-4b58-86bb-359ee5c8a979",
"responseCode": "400",
"message": "The request is missing the app_id and app_code parameters. They must both be passed as query parameters. If you do not have app_id and app_code, please obtain them through your customer representative or at http://developer.here.com/myapps."
}
Update:
What I hope to achieve, is use the POST http method. According to https://developer.here.com/documentation/fleet-telematics/api-reference.html, section "Calculates a route with additional fleet telematics features", that should be possible.
The exact request message is (without actual api key):
POST https://fleet.ls.hereapi.com/2/calculateroute.json
Content-Type: application/json
{
"apiKey": "**SNIP**",
"waypoint0": "38.72639,-9.14949",
"waypoint1": "47.54881,7.58782",
"detail": "1",
"maneuverAttributes": "none",
"linkAttributes": "none,sh",
"legAttributes": "none,li",
"currency": "EUR",
"departure": "",
"tollVehicleType": "3",
"trailerType": "2",
"trailersCount": "1",
"vehicleNumberAxles": "3",
"trailerNumberAxles": "2",
"hybrid": "0",
"emissionType": "5",
"fuelType": "diesel",
"height": "4m",
"trailerHeight": "400",
"vehicleWeight": "12000",
"limitedWeight": "40t",
"disabledEquipped": "0",
"minimalPollution": "0",
"hov": "0",
"passengersCount": "1",
"tiresCount": "14",
"commercial": "1",
"heightAbove1stAxle": "1m",
"width": "2.55",
"length": "16.5",
"mode": "fastest;truck;traffic:disabled",
"rollups": "none,country;tollsys",
"alternatives": "1"
}
This returns the following:
HTTP/1.1 401 Unauthorized
Content-Type: application/json
Date: Mon, 01 Jun 2020 11:10:09 GMT
Server: nginx-clojure
Content-Length: 74
Connection: Close
{
"error": "Unauthorized",
"error_description": "Token or apiKey is missing."
}
Whereas, passing all the same values as url arguments in a GET request works.
You need to use the following endpoint:
https://fleet.ls.hereapi.com/2/calculateroute.json?apiKey={YOUR_API_KEY}&...
See Send a Request and Calculate Toll Cost documentation pages.

gtag event purchase currency ignored, is always USD

On purchase on my ecommerce an event of type 'purchase' is triggered and correctly shown on google analytics dashboard except for the currency.
I've followed this guide, but also tried to pass parameters with 'transaction' prefix (for example 'transactionCurrency' instead of 'currency'). But I can't see any difference.
Here is how I generate payload for the event and how I send
var payload = {
"transaction_id": tid,
'value': 999.99,
'currency': "EUR", //<--this will be ignored
'items': items.map(item => ({
sku: item.sku,
name: item.description,
price: item.price,
quantity: item.qty
}))
};
gtag("event", "purchase", payload)
Here is an example of request sent:
https://www.google-analytics.com/collect?v=1&_v=j73&a=1550934340&t=event&cu=EUR&_s=2&dl=http%3A%2F%2Fmyhost.svi%2Fordini&ul=it-it&de=UTF-8&dt=ORDINI&sd=24-bit&sr=1920x1080&vp=1912x462&je=0&ec=ecommerce&ea=purchase&ev=45&_u=SCCAAUAL~&jid=&gjid=&cid=252314052.1551781012&tid=UA-xxxxxxxx-x&_gid=xxxxxx.xxxxx&gtm=2ou430&ti=C19000000021&tr=45.19&tt=8.15&ts=5&pa=purchase&pr1nm=item1&pr1pr=1.49&pr1qt=2&pr2nm=item2&pr2pr=21.85&pr2qt=2&z=1998964134
For readability the query string parameters are:
{
"v": "1",
"_v": "j73",
"a": "1550934340",
"t": "event",
"cu": "EUR",
"_s": "2",
"dl": "http%3A%2F%2Fmyhost.svi%2Fordini",
"ul": "it-it",
"de": "UTF-8",
"dt": "ORDINI",
"sd": "24-bit",
"sr": "1920x1080",
"vp": "1912x462",
"je": "0",
"ec": "ecommerce",
"ea": "purchase",
"ev": "45",
"_u": "SCCAAUAL~",
"jid": null,
"gjid": null,
"cid": "252314052.1551781012",
"tid": "UA-xxxxxxxx-x",
"_gid": "xxxxxx.xxxxx",
"gtm": "2ou430",
"ti": "C19000000021",
"tr": "45.19",
"tt": "8.15",
"ts": "5",
"pa": "purchase",
"pr1nm": "item1",
"pr1pr": "1.49",
"pr1qt": "2",
"pr2nm": "item2",
"pr2pr": "21.85",
"pr2qt": "2",
"z": "1998964134"
}
Currency should be EUR, but this is the result:
Change the ga view's settings in GA's admin to collect ecommerce data in EUR instead of USD.
if you're using one currency in your site then you won't even need to set the EUR currency in gtag.
https://support.google.com/analytics/answer/1010249?hl=en
As #Yoray mentions, change the currency setting in the view settings and that should fix it.
To add to this, if you specify a currency in the hit, you will likely see it as "Local Currency" in custom reports. (I haven't confirmed this with gtag.js).

Exporting json file of database looks different from web interface

So I am using Firebase to store my data but for some reason the json file and web interface is different. Why is the JSON file in an array? How do I fix this? Thanks!
Web interface:
Json File:
{
"data" : [ {
"age" : "35",
"agratio" : "0.9",
"alb" : "3.3",
"alkphos" : "187",
"db" : "0.1",
"diagonsis" : "yes",
"gender" : "1",
"sgot" : "18",
"sgpt" : "16",
"tb" : "0.7",
"tp" : "6.8"
}, {
"age" : "35",
"agratio" : "0.9",
"alb" : "3.3",
"alkphos" : "187",
"db" : "0.1",
"diagonsis" : "no",
"gender" : "1",
"sgot" : "18",
"sgpt" : "16",
"tb" : "0.7",
"tp" : "6.8"
}, {
"age" : "35"
}, {
"age" : "20"
} ],
"users" : {
"234234adfsdsf" : {
"username" : "hey"
},
"BbZZCTIIcJdvCCU9og905kKVvo53" : {
"email" : "andyjiang55#yahoo.com",
"username" : "andyjiang"
}
}
}
The Firebase Realtime Database internally doesn't store array. It instead stores array-like structure as regular JavaScript objects/associative arrays, with the numeric sequential indexes as keys, like you see in the console.
The Firebase SDKs and REST API (which the export JSON feature uses under the hood) have logic built in to convert array-like JSON structures back to actual arrays when they see them. So that's why the exported JSON contains an array, while the console shows the actual structure that the database stores under the hood.
Also see:
the blog post Best Practices: Arrays in Firebase.

Resources