The Graph API demonstrated will provide you with all the data that is also available via the admin console at sabek.co.ke
The following code snippet illustrates how to use sabek's graph api in your application, to login to your account and get an authorisation token and log in and request for your data
const async = require("async")
const request = require('request');
var token;
const assert = require("assert")
async.series([
function getAuthKeys(next) {
var query =
`query getToken($username:String!,$password:String!){
auth(username:$username, password:$password){
hash,
message
}
}`;
request.post({
url: 'http://localhost:9000',
form: {
query: query,
variables: JSON.stringify({
"username": "[email protected]",
"password": "testdd"
})
}
}, function(err, response, body) {
assert.ifError(err)
if (!err && response.statusCode == 200) {
// contains the token
var response = JSON.parse(body)
console.log(response.data.auth.hash)
token = response.data.auth.hash
}
next()
})
},
function getData(next) {
var query =
`query finder($id:String!){
organisation(id:$id){
name,
id,
location,
admins{
email,
contact
},
contacts{
id,
name,
number
},
groups{
id,
name,
contacts{
id,
name,
number
}
},
errors{
key,
message
}
}
}`;
request.post({
url: 'http://localhost:9000',
form: {
token: token,
query: query,
variables: JSON.stringify({
"id": "057cc8b0-a95f-11e6-bc3e-371d1cf1f0d6"
})
}
}, function(err, response, body) {
if (!err && response.statusCode == 200) {
console.log(body)
}
next()
})
}
], (err) => {
console.log("complete")
})
Querying specific data
You manipulate the query string to reduce of increase the number of things you want to be returned to you from the request,
The above query will only get you the name, and an array of admins that are in the organisation. that way you can optimise the network request to fit to only what you need in the context of your application.