Help with basic JSON query

I am new to Grafana, and I want to get some basic functionality to help create a board for our helpdesk. However, I am having some issues and I believe it is my understand of syntax.

I have a very very simple API, they queries out ticketing system, does some stuff and spits out a single integer. Currently this interger represents how many open helpdesk tickets are currently in the queue.

Pulling the URL:
https://api.url.company.com/api/tickets.php?JSON=1

And this returns:
{"value":4}

Currently no auth or anything. Trying to keep it simple.
Query Inspector shows:
Object
xhrStatus:“complete”
request:Object
method:“POST”
url:“api/datasources/proxy/1/query”
data:Object
requestId:“Q106”
timezone:""
panelId:2
dashboardId:1
range:Object
timeInfo:undefined
interval:“5m”
intervalMs:300000
targets:Array[1]
maxDataPoints:100
scopedVars:Object
cacheTimeout:null
startTime:1575298431109
rangeRaw:Object
adhocFilters:Array[0]
withCredentials:undefined
response:“4”

And testing the query builder returns a success on Browser and Server modes. Currently using “Single Stat” and Current. Panel shows “N/A”. With error “Expected response data expected array, got string”.

Okay… Tried popping the single integer into aqn array, so the API returns:
{"value":[4]}

Same error. I am quite certain this is user error, but wanted to see if someone could help me understand a little better

I did some more reading and it looks like I need the response to be a “target” and a “datapoints”. I changed the API to reflect this:

and now https://api.url.company.com/api/tickets.php?JSON=1 returns:
{"target":"value","datapoints":4}

Same error.

Looks like the issue was not that the dataset was not in an array, but the entire JSON needs to be am array.

In my php API, I just had to echo brackets…

Echo "[ “;
Echo $json_data;
Echo " ]”

Seemed happy after this

1 Like