I have a problem with this api.
This is in html
<div id="summary"></div>
This is in JS
var consuKey = "ck_b04aa6f288ee9a5495dee9c5db0a6b136350e005";
var consuSecr = "cs_1f98d389d0f9b47cd3200023864cf9b7cba50574";
function callurl() {
$.ajax({
url: 'https://test.juand.org/wc-api/v2/reports/sales?',
data:{
filter: {period: "last_week"},
consumer_key: consuKey,
consumer_secret: consuSecr
},
type: "GET",
dataType: "json"
})
.done(function(data){
JsonpCallback(data.reports)
})
.fail(function(data){
console.log("no");
})
}
function JsonpCallback(json) {
for (var i = 0; i < json.length; i++) {
$('#summary').append('<b>Descripción:</b> ' + json[i].total_sales + '<br />');
$('#summary').append('<hr />');
}
}
callurl();
I have the following error
Uncaught TypeError: Cannot read property 'length' of undefined
at JsonpCallback (VM2284:68)
at Object.<anonymous> (VM2284:60)
at fire (VM2283 jquery-2.2.4.js:3187)
at Object.fireWith [as resolveWith] (VM2283 jquery-2.2.4.js:3317)
at done (VM2283 jquery-2.2.4.js:8757)
at XMLHttpRequest.<anonymous> (VM2283 jquery-2.2.4.js:9123)
The idea is that of the result of json (total_sales) but I still do not understand why it gives me the error, if I call JsonpCallback (data.reports) if I use
JsonpCallback (data.sales)
Does not give any results
Can you help me find a solution, Thanks !!
You can see my code here