GraphQL
Our API primarily speaks GraphQL (GQL, for short). While explaining how GraphQL works is beyond the scope of this guide, there are excellent resources available on the interwebs.
Here we will introduce the basic request-response structure of the Sentiance GraphQL API.
Our default GraphQL endpoint lives at POST
https://api.sentiance.com/v2/gql
and accepts the same bearer token based authorization as our REST endpoints.Since it is possible for a single HTTP request to encompass multiple GraphQL queries with some of them succeeding and some of them failing, the endpoint always returns a 200 OK, unless something severe enough happens on the server-side to guarantee failure of the entire response (such as a 500 status code). After checking for the 200 status code, please also check the body of the response for
data
and error
properties.For other environments, please ask your sales representative or [email protected] for the custom endpoint linked to your environment.
post
https://api.sentiance.com
/v2/gql
GQL Request
While you can always discover and play around with Graphql in our Data Explorers, you might wish to programatically introspect our Schema for your own tools to parse. You can do so by firing off an Introspection Query.
QUERY
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
subscriptionType {
name
}
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type {
...TypeRef
}
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
Some examples of various GQL queries with example response are presented here. With GraphQL you can fetch as much or as little as you wish.
QUERY
query {
moment_definitions {
id
type
category
display_name
}
}
RESPONSE
{
"data": {
"moment_definitions": [
{
"id": "working_at_work",
"type": "MomentDefinition",
"category": "activity",
"display_name": "Working at work"
},
{...}
]
}
}
QUERY
query {
segment_definitions(status: ALPHA) {
id
type
category
display_name
}
}
RESPONSE
{
"data": {
"segment_definitions": [
{
"id": "mobility.passenger",
"type": "SegmentDefinition",
"category": "passenger",
"display_name": "Passenger"
},
{...}
]
}
}
QUERY
query($user_id: String!, $from:String, $to: String) {
user(id: $user_id) {
event_history(from: $from, to:$to) {
type
start
end
analysis_type
... on Stationary {
latitude
longitude
location {
significance
}
}
... on Transport {
mode
distance
}
}
}
}
VARIABLES
{
"user_id": "583e08a1cd99250700000002",
"from": "2019-03-22",
"to": "2019-03-23"
}
RESPONSE
{
"data": {
"user": {
"event_history": [
{
"type": "Stationary",
"start": "2019-03-23T19:51:49.000+01:00",
"end": "2019-03-25T08:30:21.000+01:00",
"analysis_type": "indepth",
"latitude": 51.78561,
"longitude": 42.49694,
"location": {
"significance": "home"
}
},
{
"type": "Transport",
"start": "2019-03-23T19:49:49.000+01:00",
"end": "2019-03-23T19:51:49.000+01:00",
"analysis_type": "indepth",
"mode": "walking",
"distance": null
},
{...}
]
}
}
}
QUERY
query($user_id: String!, $from:String, $to: String) {
user(id: $user_id) {
id
moment_history(from: $from, to:$to) {
start
end
analysis_type
moment_definition_id
}
}
}
VARIABLES
{
"user_id": "583e08a1cd99250700000002",
"from": "2019-03-22",
"to": "2019-03-23"
}
RESPONSE
{
"data": {
"user": {
"id": "583e08a1cd99250700000002",
"moment_history": [
{
"start": "2019-03-23T19:51:49.000+01:00",
"end": "2019-03-25T08:30:21.000+01:00",
"analysis_type": "processed",
"moment_definition_id": "home"
},
{
"start": "2019-03-23T19:22:40.000+01:00",
"end": "2019-03-23T19:49:49.000+01:00",
"analysis_type": "processed",
"moment_definition_id": "shopping_routine"
},
{...}
]
}
}
}
Last modified 2yr ago