GraphQL Occupancy API
GraphQL API v1 is going to be deprecated in 2024Q3. If you plan to use GraphQL API, please, refer to the GraphQL Occupancy API V2
- 1.1 Authorization
- 1.2 GraphQL Schema
- 1.3 Subscription Areas
- 1.4 Object & Field Descriptions
- 1.4.1 SubscirptionArea
- 1.4.2 ZoneOccupancy
- 1.4.3 LevelOccupancy
- 1.4.4 GroupOccupancy
- 1.4.5 PositionOccupancy
- 1.5 Operations
- 1.5.1 groupOccupancy
- 1.5.2 findGroupOccupancies
- 1.5.3 findPositionOccupancies
- 1.5.4 createSubscriptionArea
- 1.5.4.1 Subscription Area Expiration
- 1.5.5 onSubscriptionAreaUpdates
- 1.5.6 updateSubscriptionArea
- 1.6 Use cases
- 1.6.1 Displaying all parking groups within 2km in a mobile app
- 1.6.2 Getting group occupancy summary and each position status and labels to be able to calculate occupancy statistics by labels using only one query
- 1.6.3 Displaying individual parking positions when a user approaches his desired parking location
- 1.6.4 Displaying occupancy statuses of positions with label “Disabled” within 2km radius
- 1.6.5 Displaying live parking statuses within 2km radius
- 1.6.6 Displaying live occupancies per level in a zone (multistory car park)
- 1.6.7 Displaying live occupancies of disabled spaces per level in a zone
- 1.6.8 Extend subscription area expiration
- 1.7 Postman Collection
- 2 Example Python Client
GraphQL Occupancy API offers similar functionality to REST Occupancy API, however, there are additional benefits to using GraphQL.
You can select the fields you want to receive from the API. By requesting only the required fields from the API you can decrease traffic and consequently increase load speed.
Additionally, GraphQL Occupancy API supports subscriptions, which allows you to receive real-time occupancy updates.
Authorization
In order to authorize with this API, you need to add the following header to your request:
Key | Value |
---|---|
Authorization | <your token> |
Your token can be obtained from the Company Info section of the Nwave’s console.
You are able to call API not more frequent, than 300 times per 5 minutes interval with use of the same token. If amount of requests exceeds the limit, API reponds with error until the end of 5 minutes interval.
GraphQL Schema
The following GraphQL schema describes data types and operations that can be performed.
Subscription Areas
A subscription area is an object that has two main functions:
Filtering of the incoming position updates
Defining the format of updates that is received by subscribers
There are two types defined in the GraphQL schema for Subscription Areas:
SubscriptionAreaNoUpdates
- this type is returned when you create or update a Subscription Area. It does not have ‘updates’ & ‘updateTime’ fields as updates are only returned to active subscriptions.
Subscription areas expiry 5 minutes after creation. Any update of a subscription area, including an empty one, will extend the expiration time by 5 minutes from the time of update.
SubscriptionAreaWithUpdates
- this type is returned to subscribers and as the name suggests it contains the ‘updates’ & ‘updateTime’ fields.
Subscription Area Filters
Subscription Areas filter the incoming updates and only notify the subscribers if the incoming position update matches all of the filters. Subscription Area filters can also be split into 2 categories:
Hierarchical Filters: zoneId, groupId, levelId, floorNumber, labels
Geospatial Filters: lat, lon, radius
A match is when all position attributes are a subset (⊆) of the Subscription Area filters and it implies that a given position is inside a Subscription Area.
The following example is a valid match between Subscription Area and Position Update.
Position
zoneId: 1
groupId: 2
levelId: 3
floorNumber: 4
labels: ['EV', ‘Disabled’]
lat: 0.0
lon: 0.0
Subscription Area
zoneId: [1, 2, 3]
groupId: [1, 2, 3]
levelId: [3]
floorNumber: null
lables: ['EV', ‘Disabled’, ‘VIP’]
lat: 0.0
lon: 0.0
radius: 100
Subscription Area Updates
The updates field of a Subscription Area can contain a list of 4 different types. All types within the updates list are the same. The type you will receive in the updates field depends on the granularity you choose.
Granularity | Updates Type |
---|---|
Zone | ZoneOccupancy |
Level | LevelOccupancy |
Group | GroupOccupancy |
Position | PositionOccupancy |
Object & Field Descriptions
SubscirptionArea
id - subscription area id
location - center coordinates of the search area
radius - radius from the center in meeters that creates the search area
zoneId - list of zone ids to match
levelId - list of level ids to match
floorNumber - list of floor numbers to match
groupId - list of group ids to match
labels - list of labels to match
granularity - defines the updates type
expiresOn - timestamp of subscription area expiration
udpates - occupancy updates for a subscription area
updateTime - timestamp of the occupancy update
ZoneOccupancy
id - zone id
name - zone name
projectId - project id
summary - summary of occupancies in the Zone
LevelOccupancy
id - level id
name - level name
zoneId - zone id
floorNumber - floor number of a level
summary - summary of occupancies on a Level
GroupOccupancy
id - group id
zoneId - zone id
levelId - level id
name - group name
groupType - group type e.g. marked_bay
customId - user defined group id
location - сenter coordinates of a group
positionOccupancy - list of PositionOccupancy objects for a group
summary - summary of occupancies in the Group
PositionOccupancy
id - position id
customId - custom id
groupId - group id
occupancyStatus - ‘occupied’, ‘free’ or null
statusChangeTime - timestamp of last occupancyStatus change
location: coordinates of a position
Operations
The following operations can be performed using either Postman or curl command except for subscription operations.
groupOccupancy
This query will return the occupancy of a single group.
Query
query MyQuery {
groupOccupancy(id: 123) {
id
customId
name
location {
lat
lon
}
positionsOccupancy {
customId
id
groupId
labels
location {
lat
lon
}
occupancyStatus
statusChangeTime
}
}
}
Response
{
"data": {
"groupOccupancy": {
"id": 3544,
"customId": null,
"name": "Foo",
"location": {
"lat": 51.493601937687224,
"lon": -0.12852029611716095
},
"positionsOccupancy": [
{
"customId": "",
"id": 1,
"groupId": 123,
"labels": null,
"location": {
"lat": 51.49360068522545,
"lon": -0.1286061268139623
},
"occupancyStatus": "Free",
"statusChangeTime": "2021-01-27T19:22:47.548+00:00"
},
{
"customId": "",
"id": 2,
"groupId": 123,
"labels": null,
"location": {
"lat": 51.493601937687224,
"lon": -0.12852029611716098
},
"occupancyStatus": "Occupoed",
"statusChangeTime": "2021-01-27T18:56:53.502+00:00"
}
]
}
}
}
findGroupOccupancies
This query will return a list of group occupancies.
Query
Response
findPositionOccupancies
This query will return a list of position occupancies.
Query
Response
createSubscriptionArea
This mutation will create a new subscription area.
Subscription Area Expiration
By default, subscription areas expire 5 minutes after creation. Once a subscription area is expired, it cannot be extended and subscribers will stop receiving updates.
Mutation
Response
onSubscriptionAreaUpdates
This subscription will subscribe to occupancy updates inside an area.
Selected updates object type must correspond to the granularity of the created search area:
granularity: Position → updates { … on PositionOccupancy }
granularity: Group → updates { … on GroupOccupancy }
If you are unsure of the granularity for your subscription area, you can specify both types inside the updates.
Subscription
Update
updateSubscriptionArea
This mutation will update an existing subscription area.
Mutation
Response
Use cases
Query | Use case |
---|---|
Displaying all parking groups within 2km in a mobile app
| |
Getting group occupancy summary and each position status and labels to be able to calculate occupancy statistics by labels using only one query | |
Displaying individual parking positions when a user approaches his desired parking location | |
| Displaying occupancy statuses of positions with label “Disabled” within 2km radius |
Displaying live parking statuses within 2km radius | |
Displaying live occupancies per level in a zone (multistory car park) | |
Displaying live occupancies of disabled spaces per level in a zone
| |
Extend subscription area expiration |
Postman Collection
Download Postman Collection here:
Importing Collection
Click import in My Workspace section.
Upload the collection file and click
Import.
Adding API key to Postman Environment
This collection uses the api_key variable to add an authorization token to the x-api-key header.
To create a new environment click on the eye icon near the top right corner.
2. Click Add to add a new environment.
3. Add the gql_api_key variable name and your token in the initial value.
4. Select the New Environment from the list.
5. You can now test the requests in the GraphQL Occupancy Collection.
Example Python Client
There is a simple GraphQL client example in our Github repository. It is developed in Python and let you start getting data on demand and subscribe on occupancy change notifications.
Please, follow the instructions in the README.md to prepare your invironment for running example.