Implementing a global shot listener

1. Acquiring an API key

The first step is to acquire an API key for the local Driving Range server, with the appropriate permissions to be able to listen to all shots in the Driving Range.

2. Exchange API key for a JWT Bearer Token

After acquiring an API key, you need to exchange it for a JWT token, which is the normal way to make authenticated calls to the Range Server API. In order to do that you need to make a call to the following endpoint:

Content-Type: application/x-www-form-urlencoded

POST /connect/token
    grant_type=api_key
    &api_key={YOUR-API-KEY}

Host: localsite.trackmanrange.com

A successful response will look like the following

{
    "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0NzkyOTk2N",
    "token_type": "Bearer"
}

3. Acquire a Url to the Measurements Websocket channel

Make a POST request to the measurements_ticket link from /api, in order to acquire a Url for the Measurements Websocket channel, making sure to pass the previously acquired JWT token to the Authorization header of the request:

POST /api/measurements/ticket
Host: localsite.trackmanrange.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0NzkyOTk2N

A successful response will look like the following

{
    "ticketId": "12bc5896-6ca3-49a3-b812-31b0ad142293",
    "_links": {
        "measurements": {
            "href": "ws://localsite.trackmanrange.com/ws?type=all&ticketId=12bc5896-6ca3-49a3-b812-31b0ad142293"
        },
        "subscribe": {
            "method": "POST",
            "href": "https://localsite.trackmanrange.com/api/measurements/subscribe"
        }
    }
}

4. Establish a connection to the Measurements Websocket channel

Now that we have the url to the appropriate Websocket channel, connect to it using the measurements link acquired in the previous step.

5. Subscribe to measurements from

A) all bays

Finally, make a POST request to the subscribe link that was returned in the response of the 3rd step above, in order to start receiving measurements from any bay in the Driving Range:

POST /api/measurements/subscribe
Host: localsite.trackmanrange.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0NzkyOTk2N

B) a specific bay

When you receive the ConnectionEstablishedEvent message on the WebSocket, make a POST request to the subscribe link that was returned in the response of the 3rd step above, in order to start receiving measurements from a specific bay in the Driving Range (Bay Ids are retrieved using the /api/bays endpoint):

{
    "Type": "ConnectionEstablishedEvent",
    "Payload": { "ConnectionId": "b3d496e3-22a4-425d-a2ce-e785557e2a64"}
}
POST /api/measurements/subscribe
Body: { "ConnectionId":"b3d496e3-22a4-425d-a2ce-e785557e2a64", "BayIds":["1c963d37-8958-4252-9d90-5d9a6fe90f71"]}
Host: localsite.trackmanrange.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0NzkyOTk2N