Back to top
Vastuu Group

Launch an application in 10 minutes!

Last updated: July 7, 2020
|
Reading time: 7 min

Let's build a simple Hello Data product app in Platform of Trust Sandbox!

Step 1: Clone the boilerplate application

You can deploy apps wherever you want. Even locally. We have a sample app that you can configure and follow the rest of the guide to make a simple "hello data product" app.

Clone Sample App

Step 2: Register your application

Check out this guide on how to register your application . During application registration, you will be requiring credentials to make API calls and to create a Group ID .

By the way, you need to have an account too in Platform of Trust Sandbox.

Register to Sandbox

Sample request to Application API to create an App:

curl --request POST \
  --url https://api-sandbox.oftrust.net/apps/v1 \
  --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzY29w...DVs5aaf' \
  --header 'Content-type: application/json' \
  --data '{
    "name": "Example Application",
    "description": "Application description",
    "privacyPolicyUrl": "http://example.com/privacy.html",
    "webPageUrl": "http://example.com/application.html",
    "iconUrl": "http://example.com/icon.png",
    "scopes": "",
    "defaultScopes": "",
    "redirectUris": "https://example.com/auth-callback",
    "defaultRedirectUri": "https://example.com/auth-callback",
    "groupId": "7a5c0197-7e05-4180-8d6f-104911880eee"
  }'

On success, you'll get a response similar to this:

{
  "@context": "https://standards.oftrust.net/v2/Context/Identity/Digital/Software/App/",
  "@type": "App",
  "@id": "8c40d6d4-2dbb-4f8f-987f-5c68e7475d79",
  "data": {
    "iconUrl": "http://example.com/icon.png",
    "privacyPolicyUrl": "http://example.com/privacy.html",
    "description": "Application description",
    "webPageUrl": "http://example.com/application.html",
    "name": "Example Application"
  },
  "metadata": {
    "createdAt": "2020-02-14T07:18:22+00:00",
    "createdBy": "e224629d-3f4f-4cb2-8823-fdc839e5da98",
    "updatedAt": "2020-02-14T07:18:22+00:00",
    "updatedBy": "e224629d-3f4f-4cb2-8823-fdc839e5da98"
  },
  "inLinks": [],
  "outLinks": [],
  "client": {
    "clientId": "8c40d6d4-2dbb-4f8f-987f-5c68e7475d79",
    "redirectUris": "https://example.com/auth-callback",
    "defaultRedirectUri": "https://example.com/auth-callback",
    "scopes": "",
    "defaultScopes": "",
    "clientSecrets": [
      "4RbY09PR16F74VacbFhIsxzAJTytJfplpgZRdqE_tp4"
    ]
  },
  "tokens": [
    {
      "access_token": "wvkBrsvjBEigwd-PA...1h5vweXnzCEvpkapESHz6sxE",
      "expires_in": 63072000,
      "token_type": "Bearer"
    },
    {
      "access_token": "CkT5COQfHtbuih1a2...1h5vweXnzCEvpkapESHz6sxE",
      "expires_in": 63072000,
      "token_type": "Bearer"
    }
  ]
}

NOTE: Make sure to save clientId, clientSecrets and access_token for future use.

Did you know that we have an Insomnia REST Workspace which you can use to access and test Platform of Trust APIs in Sandbox? Read the following guide to access and use the workspace.

Read Insomnia Workspace Guide

Step 3: Consume Data Product

We have ready-made data products for you to use in our Sandbox .

More data products can be queried with our Product API :

Product API 1.0 - List all products

const request = require('request'); request('https://api-sandbox.oftrust.net/products/v1', { json: true }, (err, res, body) => { if (err) { return console.log(err); } console.log('response', body); });

Use the following python script to configure your app credentials: CLIENT_SECRET, ACCESS_TOKEN and add the productCode of the Data Product of your choice:

import json
import hmac
import hashlib
import base64
import http.client
from datetime import datetime
‚Äč
# App secret and token
secret = "jyfExri29...Utmu4RYKQ"
app_token = "eyJ0eXAiOiJKV...G15CiU83mxqjXXE9U"
timestamp = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.000Z")
body = {
    "@context": "https://standards.oftrust.net/v2/Context/DataProductParameters/Sensor/",
    "timestamp": timestamp,
    "productCode": "master-30-temperature",
    "parameters": {
        "ids": [
            {"id": "Valtuustotalo_kokoushuone4-temp"}
        ],
        "startTime": "2020-02-10T13:06:40+00:00",
        "endTime": "2020-02-10T21:20:54+00:00",
        "dataTypes": ["MeasureAirTemperatureCelsiusDegree"]
    },
}
body_hash = json.dumps(
    body, sort_keys=True, indent=None, separators=(",", ": ")
).strip()
digest = hmac.new(
    secret.encode("utf-8"), body_hash.encode("utf-8"), hashlib.sha256
).digest()
signature = base64.b64encode(digest).decode()
conn = http.client.HTTPSConnection("api-sandbox.oftrust.net")
headers = {
    "content-type": "application/json",
    "x-pot-signature": signature,
    "x-app-token": app_token,
}
conn.request("POST", "/broker/v1/fetch-data-product", json.dumps(body), headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Here,

  • x-app-token is the access_token you obtained while registering an Application in step 2.
  • secret refers to the clientSecrets from that application.
  • timestamp refers to the time when the request was sent. This needs to be in RFC3339 format. timestamp may or may not depend on the translator/connector being used in the data product. Read more on translators in the Setup Translator guide.
  • productCode is from the Data Product you want to use. Read more about Data Products from the Data Product 101 guide.
  • parameters are additional parameters that the connector needs. Different products and connectors may require different parameters. You should check the parameters list from Data Provider's translator.
  • x-pot-signature is A HMAC-SHA256 signature in base64 encoded format. The signature is created from the request payload and clientSecrets obtained while registering an Application in step 2. Read more on x-pot-signature from the Broker API documentation.

Checkout Consume Data Product guide for more information.

NOTE: When computing body_hash, make sure the separators are in the correct format. For version 1 of Platform of Trust APIs/connectors, the separator has the syntax: ",", ": ".

Step 4: Run it

Save the script. Execute the python script in your terminal with the following command:

python script_name.py

On success, depending on the connector accepting the parameters and returning a response from the data source, you should see a response similar to the following:

{
    "@context": "https://standards.oftrust.net/v2/Context/DataProductOutput/Sensor/", 
    "data": {
        "sensors": [{
            "id": {"id": "Valtuustotalo_kokoushuone4-temp"}, 
            "measurements": [{
                "timestamp": "2020-02-10T13:30:00+00:00", 
                "value": 22.0, 
                "@type": "MeasureAirTemperatureCelsiusDegree"
            }, 
            {
                "timestamp": "2020-02-10T14:00:00+00:00", 
                "value": 21.0, "@type": 
                "MeasureAirTemperatureCelsiusDegree"
            }, 
            {
                "timestamp": "2020-02-10T14:30:00+00:00", 
                "value": 20.0, 
                "@type": "MeasureAirTemperatureCelsiusDegree"
            }, 
            .
            .
            .
            {
                "timestamp": "2020-02-10T21:00:00+00:00", 
                "value": 22.0, 
                "@type": "MeasureAirTemperatureCelsiusDegree"
            }
        ]
    }]
  }, 
   "signature": {
        "type": "RsaSignature2018", 
        "created": "2020-06-30T07:31:56+00:00", 
        "creator": "https://api-external-sandbox.oftrust.net/dummy-translator/v1/public.key", 
        "signatureValue": "vPWjptw...GnbseEP0o3A=="
   }
}

This ensures the registered Application is functioning properly and is capable to consume harmonized data fetched by the Data Product.

Ready to get started?

Login to Platform of Trust Sandbox

Have a wishlist?

Send Us Feedback