First released in version: 3.2 / Last updated in version: 3.9

Using the Application REST API

Overview

The Application REST API allows you to view or create objects and properties in your user data model. Once you have installed the REST API, you can view and interact with the Swagger Doc, use Bearer authentication and send requests to the API endpoints.

Authentication

From version 3.8 SP5, the SmartSpace Application REST API supports Bearer authentication. From version 3.9, the REST API requires authentication by default. The two OAuth flows that Ubisense support are Authorization Code Flow with PKCE and Client Credentials flow.

Depending on the OAuth method that you use, you need to set up either a role or scope when configuring your authentication. If you are using the PKCE flow, you need to add a role called "smartspace-rest-api-access-role". Only users that are members of this role can access the REST API. If you are using the Client Credentials flow, you need to add a scope called "smartspace-api-scope". Only applications that are added to this scope can access the REST API.

Configuring the Application REST API

Once you have configured your authentication, you will have the basic information needed to configure the settings in the REST API. On Linux, these are configured in /etc/ubisense/restapi.json. On Windows, they are in localsettings.json in the REST API installation folder; this is normally C:\Program Files (x86)\Ubisense 3\WebApiCore\Web.

The following sections are needed in the REST API settings:

  • AllowHosts, to support CORS headers and allow access from external web pages

  • JWTAuth, to configure the application information, and

  • AuthOptions, to require authentication for all access

An example of the REST API settings is shown below. Replace the following parameters with values from your authentication configuration:

  • metadataAddress: The URL where your OpenID Connect configuration is published.

  • authority: The base URL of your authorization server.

  • audience: The identifier for your API that clients must include in their token requests.

  • nameClaim: The claim in the token that contains the username.

  • validIssuers: An array of issuer URLs that are considered valid. Tokens from other issuers will be rejected.

  • validateLifetime: A boolean value indicating whether the token’s lifetime should be validated.

  • requireHttpsMetadata: A boolean value indicating whether HTTPS is required for the metadata endpoint.

Copy
"JWTAuth": {
  "metadataAddress": "https://<your-auth-server>/path/to/.well-known/openid-configuration",
  "authority": "https://<your-auth-server>",
  "audience": "<your-api-identifier>",
  "nameClaim": "preferred_username",
  "validIssuers": ["https://<your-auth-server>/path/to/issuer"],
  "validateLifetime": true,
  "requireHttpsMetadata": false
}

The parameter “validIssuers”: should be the list of valid issuers. For multi-tenant organizations, you may configure multiple valid issuers with different tenant IDs.

Once you have saved the settings, restart the REST API service, if using Linux, or the SmartSpaceCoreApi application pool, if using Windows/IIS.

Fetching the token

After configuring the REST API settings, you can fetch and use the JWT. The following code snippet shows an example of fetching and using the token for the Client Credentials flow in C#.

Copy

Fetching the token

internal class AuthenticationService{
    private readonly HttpClient _httpClient;
    public AuthenticationService(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }
    public async Task<string> GetAccessTokenAsync(string clientId, string clientSecret, Uri tokenEndpointUri)
    {
        var clientCredentials = new FormUrlEncodedContent(new[]
        {
        new KeyValuePair<string, string>("grant_type", "client_credentials"),
        new KeyValuePair<string, string>("client_id", clientId),
        new KeyValuePair<string, string>("client_secret", clientSecret),
    });
        var response = await _httpClient.PostAsync(tokenEndpointUri, clientCredentials);
        response.EnsureSuccessStatusCode();
        var content = await response.Content.ReadAsStringAsync();
        var tokenResponse = JsonSerializer.Deserialize<Dictionary<string, object>>(content);
        return tokenResponse["access_token"].ToString();
    }
  }
Copy

Using the returned token

var accessToken = await _authenticationService.GetAccessTokenAsync(
    "sample-console-app",
    "<client_secret>",//Replace this with the client secret. This is a secret and should be treated as such in production scenarios
    new Uri("<token-endpoint-url>") // Replace with your token endpoint url        
  );
  _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  const string apiUrl = "http://localhost:5001/api/TagTypes";
  var response = await _httpClient.GetAsync(apiUrl);
  if (response.IsSuccessStatusCode)
  {
      var content = await response.Content.ReadAsStringAsync();
      Console.WriteLine("Response Content:\n" + content);
  }
  else
  {
      Console.WriteLine($"Error: {response.StatusCode}");
  }

An API specification JSON file is provided which can be used to generate your client code. The file can be found at http://localhost/smartspaceapi and clicking the link under the title.

dowload link for the API secification json file

Requests and endpoints

This section provides an overview of the requests and endpoints needed to view or create objects and properties in your user data model. Navigate to http://localhost/smartspaceapi to view the Swagger Doc and interact with the requests.

ObjectLocations

ObjectProperties

ObjectTags

TypeHierarchy

TypeObjects

TypeProperties

Schemas

ObjectComplexProperty

Parameter Type

Value

Object string

The object in "Type/Name" format

nullable: true

PropertySignature string

The signature for the property in "Key Text(Type)..." form

nullable: true

PropertyType string

The type the property evaluates to

nullable: true

PropertyKey

integer($int32)

The position in the signature where is object appears

PropertyRows  

All rows for this property, object, key combination

nullable: true

PropertyRow

PropertyKeys: 

The key columns of the property

string

PropertyValue:

The final or value column of the property

string

minLength: 1

ObjectLocation

Parameter Type

Value

Object string

The object in "Type/Name" format

minLength: 1

X

number($double)

The location x coordinate

Y

number($double)

The location y coordinate

Z

number($double)

The location z coordinate

Theta

number($double)

The orientation in radians (optional)

nullable: true

ObjectProperty

Parameter Type

Value

Object string

The object in "Type/Name" format

nullable: true

PropertyName string

The property name

nullable: true

PropertyValue string

The propery value

nullable: true

ObjectTag

Parameter Type

Value

Object string

The object in "Type/Name" format

nullable: true

Tag string

The tag Id in dashed decimal form

nullable: true

Battery string

The tag battery status. Possible values include OK, Warning, Failing and Unknown.

nullable: true

Activity string

The tag activity. Possible values include Active or Inactive.

nullable: true

TagType string

The tag type.

nullable: true

TagPosition  

Vector3D

X: number($double)

Y: number($double)

Z: number($double)

ProblemDetails

Parameter Type

Value

type string

nullable: true

title string

nullable: true

status

integer($int32)

nullable: true

detail string

nullable: true

instance string

nullable: true

PropertyRow

Parameter Type

Value

PropertyKeys string

The key columns of the property

PropertyValue string

The final or value column of the property

minLength: 1

TagModel

Parameter Type

Value

Tag string

The tag Id in dashed decimal form

nullable: true

Battery string

The tag battery status. Possible values include OK, Warning, Failing and Unknown.

nullable: true

Activity string

The tag activity. Possible values include Active or Inactive.

nullable: true

TagType string

The tag type.

nullable: true

Object string

The object in "Type/Name" format

nullable: true

TypeHierarchy

Parameter Type

Value

Type string

nullable: true

Ancestors string

nullable: true

Descendants string

nullable: true

TypeObject

Parameter Type

Value

Object string

The object in "Type/Name" format

nullable: true

TypeProperties

Parameter Type

Value

Type string

The object type

nullable: true

Properties string

The type's properties

nullable: true

Vector3D

Parameter Type

Value

X number($double)

The location x coordinate

Y number($double) The location y coordinate
Z number($double) The location z coordinate