How to load JSON Data on google visualization Chart? - google-visualization

I'm new with google-visualization. I'm developing a full dashboard like google full dashboard example
Following the example I declare data like this:
var data = google.visualization.arrayToDataTable([
['CodiceCliente', 'Cliente', 'QtàO13', 'QtàO14','UM'],
['0000038893', 'Coop',300,350, 'CT'] .... ]);
Now I want to load data from server. I create a Json like this:
{
"cols": [
{"id": "codiceCliente","label": "Cod. Cliente","type": "string"},
{"id": "clienteDesc","label": "Cliente","type": "string"},
{"id": "qtaO13","label": "Qtà O13","type": "number"},
{"id": "qtaO14","label": "Qtà O14","type": "number"},
{"id": "um","label": "UM","type": "string"}
],
"rows": [
{
"c": [
{"v": "0000038893"},
{"v": "Coop"},
{"v": "300"},
{"v": "350"},
{"v": "CT"} ]
},
{.... }, ... ]}
In html page i use this code to get data from server:
var jsonData = $.ajax({
url: "getJson.do",
dataType:"json",
async: false
}).responseText;
var data = google.visualization.DataTable(jsonData);
When I open the page, I get this error: " Object # has no method 'zg' at format+it,default+it,ui+it,controls+it,corechart+it.I.js:183 "
where am I wrong? JSON format is wrong?

You are missing the new keyword in the DataTable constructor. It should be:
var data = new google.visualization.DataTable(jsonData);

Related

Find nested variable inside json payload

I'm using the find function in postman tests to save environment variables,
the find function works great when I'm looking for a variable, But I cannot get it to work when looking for variables inside an object
My payload looks something like this
{
"name": "product1",
"state": {
"DefinitionId": "productcard",
"Id": "32919b8c-984e-46c3-933d-51d3c621d4cf"
},
"status": "Done"
},
{
"name": "product2",
"state": {
"DefinitionId": "productaccount",
"Id": "4999b8c-984e-46c3-933d-55d3c621d4cf"
},
"status": "NotDone"
},
with the _find function I can find variables through the name variable
var steps = _.find(resBody, {
name: "product1",
})
pm.environment.set(steps.name, steps.state.Id);
But what If I want to search by DefinitionId?
I have tried stuffs like this
_.find(resBody, {
name.state: "product1",
}) <--did not work
_.find(resBody.state, {
name.state: "product1",
}) <--did not work [returns object object]
Thanks in advance.
This should return the an object by a DefinitionId search, if that's what you mean?
var result = resBody.find(x => x.state.DefinitionId === "productaccount");

Extracting data in twilio studio liquid template

I am trying to get the phone number in studio liquid-template.No matter what pattern I turn into it never extract the data.considering the data is a return object from a http post
{{widgets.http_1.parsed.attributes.phone}}
{{widgets.http_1.parsed["attributes"].phone}}
{{widgets.http_1.parsed.[attributes].phone }}
{{widgets.http_1.body["attributes"].phone }}
{{widgets.http_1.body.attributes.phone}}
{{widgets.http_1.parsed["attributes"].phone}}
{accountSid=ac, activityName=Offline, activitySid=wa,
attributes={
"onlyOutboundCallMode": false,
"routing": {
"skills": [
"english"
]
},
"email": "#gmail.com",
"phone":"12323"
},
available=false}
For deeply nested objects, you will need to parse the data outside Studio. Take a look at the Studio execution logs of your Studio flow. See if the HTTP Request widget was able to parse the JSON structure.
Returning this structure worked for Studio which parsed it:
let respObj = {
accountSid: "ac",
activityName: "Offline",
activitySid: "wa",
attributes: {
onlyOutboundCallMode: false,
routing: {
skills: [
"english"
]
},
email: "#gmail.com",
phone:"12323"
},
available: false}
Result in Studio:
"parsed": {
"accountSid": "ac",
"activityName": "Offline",
"activitySid": "wa",
"attributes": {
"onlyOutboundCallMode": false,
"routing": {
"skills": [
"english"
]
},
"email": "#gmail.com",
"phone": "12323"
},
"available": false
}

How to verify array response values in postman test?

Expected Test Scenario: Need to validate the array response "Values" for the "Key: id".
I am using the test code:
pm.test("Your test name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.id).to.contains(16);
});
Getting the error:
AssertionError: object tested must be an array, a map, an object, a set, a string, or a weakset, but undefined given.
Response Body:
[
{
"id": 2,
"Name": "Hello",
"Country": "India"
},
{
"id": 4,
"Name": "thankyou",
"Country": "UK"
},
{
"id": 16,
"Name": "how are you",
"Country": "USA"
},
{
"id": 18,
"Name": "Good morning",
"Country": "Italy"
},
{
"id": 25510,
"Name": "Bonjour",
"Country": "France"
}
]
Anyone could help me in sorting out this please.
The response is not a JSON object but JSON array.
pm.response.json() will have you full json which is in the form :
[ {}, {} ]
so the JSON object with id 16 is the 3rd element in the array so first call jsonData[3] and then get id in it.
But still you will get error because what you are getting is a "integer" so cannot use contains with it . Use equal instead
pm.test("Your test name", function () {
var jsonData = pm.response.json();
pm.expect(jsonData[2].id).to.equal(16);
});
or if you want to use contains instead , then get response as text using pm.response.text():
pm.test("Your test name", function () {
var jsonData = pm.response.text();
pm.expect(jsonData).to.contains(16);
});

How to send a request?

I need to send a request with the following data
"order": {
"server_callback_url": "http://site.id/callback",
"currency": "UAH",
"amount": "1400",
"order_type": "settlement",
"response_url": "http://site.id/test/responsepage/",
"order_id": "test1234561467462099.19",
"operation_id": "test1234561467462099.19",
"order_desc": "test order",
"merchant_id": 700001,
"receiver": [
{
"requisites": {
"amount": 100,
"merchant_id": 500001
},
"type": "merchant"
},{
"requisites": {
"amount": 200,
"merchant_id": 600001
},
"type": "merchant"
},
]
}
I need to send them to https://api.fondy.eu/api/settlement
But I never did that. I am not familiar with DRF at all. Tell me how to implement it, please.
If we visit the endpoint, it says that only POST methods are allowed. We can make a POST request for example with the requests package.
import requests
data = {
"order": {
"server_callback_url": "http://site.id/callback",
"currency": "UAH",
"amount": "1400",
"order_type": "settlement",
"response_url": "http://site.id/test/responsepage/",
"order_id": "test1234561467462099.19",
"operation_id": "test1234561467462099.19",
"order_desc": "test order",
"merchant_id": 700001,
"receiver": [
{
"requisites": {
"amount": 100,
"merchant_id": 500001
},
"type": "merchant"
},{
"requisites": {
"amount": 200,
"merchant_id": 600001
},
"type": "merchant"
},
]
}
}
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
response = requests.post('https://api.fondy.eu/api/settlement', data=data, headers=headers)
The header can be important, since it tells you in what format you make your reqest, and some APIs do not work if you do not set the Content-type properly.
The response is here a Response object, and you can parse the response to a Python dictionary with:
response.json()
locally this gives me:
{'response': {'error_code': 1002,
'error_message': 'Application error',
'request_id': 'iUxQzJfyBuxdI'}}
The status code is 200, so that probably means that the callback you specified was not valid (or some other items in your request).
You could use DRF as the documentation :
https://www.django-rest-framework.org/tutorial/2-requests-and-responses/
Or without DRF :
# importing the requests library
import requests
# api-endpoint
URL = "https://api.fondy.eu/api/settlement"
# defining a params dict for the parameters to be sent to the API
data =
"order": {
"server_callback_url": "http://site.id/callback",
"currency": "UAH",
"amount": "1400",
"order_type": "settlement",
"response_url": "http://site.id/test/responsepage/",
"order_id": "test1234561467462099.19",
"operation_id": "test1234561467462099.19",
"order_desc": "test order",
"merchant_id": 700001,
"receiver": [
{
"requisites": {
"amount": 100,
"merchant_id": 500001
},
"type": "merchant"
},{
"requisites": {
"amount": 200,
"merchant_id": 600001
},
"type": "merchant"
},
]
}
# sending get request and saving the response as response object
r = requests.POST(url = URL, data= data)
# extracting data in json format
data = r.json()
Maybe you would like to try the API before writing code, there is tool like postman to do this quickly :)

Access meta reply message

My backed is giving me some information about the reply in a meta field. For example, when going to #/phoneNumbers/phonelocations/index a request to /api/phonelocations is sent, and this is the data received:
{
"meta": {
"api_action": "find_all",
"api_id": "phonelocations",
"content_type": "application/json",
"error_code": 200,
"errors": [
{
"admin_message": "",
"code": 200,
"message": ""
}
],
"message": "Successfully read phonelocations",
"success": true
},
"phonelocations": [
{
"_id": "0",
"city": "Berlin",
"count": 10,
"country": "DE",
"country_name": "Germany",
"loctype": "GEO",
"loctype_human": "Geographical number",
"subtype": "49GEO",
"subtype_human": "German geographical number",
"type": "phonelocation-faketype"
},
...
]
}
This is present in all replies coming from the backend. I would like to use the message in _reply_meta.message to display it to the user. Is there a standard way in Ember to access the meta information of the replies?
Just use store.metadataFor(type), in your case:
var meta = this.store.metadataFor('phonelocation');
// all metadata is in meta object
meta.message // => "Successfully read phonelocations"
See this in action http://jsfiddle.net/marciojunior/3vfQD/