Back to top
Vastuu Group

Consume Data Products

Last updated: March 16, 2021
|
Reading time: 3 min

Tags: V1 APIs, Connector, Data Product, Harmonized Data

One of the core features of the Platform of Trust to enable registered apps to request and obtain data via available data products. Data products aid apps to fetch data from sensors, devices and IoT devices.

This guide is meant for developers who is familiar with Platform of Trust and its main concepts such as: Identities, Authorizations token and Data products. You can read about these topics in our guides as well e.g. Data product 101 guide.

Note: Keep in mind, that version 1 APIs of Platform of Trust have been used in this demonstration.

Fetch a data product via Broker API

One of the most important features of Platform of Trust is to connect 3rd party data providers and any user on the platform. Thus you should be able to fetch data products via Broker API. Broker API will process your request and pass it to target Data Provider's translator.

consume data product at the Platform with registered application

Example:

curl --request POST \
  --url https://api-sandbox.oftrust.net/broker/v1/fetch-data-product \
  --header 'content-type: application/json' \
  --header 'x-app-token: eyJ…FY' \
  --header 'x-pot-signature: MYZlyZR+V5+auLqMMXCUnvaVHfD2wvSujFreOrMrASw=' \
  --data '{
    "timestamp": "2019-10-25T00:00:00.000Z",
    "productCode": "prh-business-identity-data-product",
    "parameters": {
        "businessId": "0831312-4"
    }
}'

Required headers:

x-app-token: access token of application you should have created before. You can read more about application in Register an application guide.
x-pot-signature: A HMAC-SHA256 signature in base64 encoded format. The signature is created from the request payload and the app's client secret.

Basic example in Python on how to generate x-pot-signature :

body = {
    "timestamp": generate_RFC3339(),
    'productCode': 'prh-business-identity-data-product',
    "parameters": {
        "businessId": "2980005-2"
    }
}

# Client secrets
secret = "P8qNkpXkfLe_OQa_2ydHRgzFR2_GuIoyUoMtf8zcLZ0"

# The keys MUST be sorted, without indentation 
# and separators comma (,) and colon (:) specified.

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()
return signature

Optional header:

x-user-token: The currently logged in user's OAuth bearer token. In case data product is user-specific.

Required parameters:

timestamp: The timestamp when the request was sent. RFC3339 format.
productCode: The product code of the data product you want to fetch.
parameters: Optional additional parameters that the translator needs. Different products and translator requires different parameters. You should check parameters list from Data Provider's translator API.

Response:

{
  "@context": "https://standards.lifeengine.io/v1/Context/Identity/Thing/HumanWorld/Product/DataProduct",
  "data": {
    "@context": "https://standards.oftrust.net/contexts/data_product-translator_test_data.jsonld",
    "@type": "BusinessIdentity",
    "totalResults": 1,
    "offset": 0,
    "items": [
      {
        "name": "Platform of Trust Oy",
        "businessId": "2980005-2",
        "companyForm": "OY",
        "registrationDate": "2019-03-01"
      }
    ]
  },
  "signature": {
    "type": "RsaSignature2018",
    "created": "2019-10-28T18:42:51+00:00",
    "creator": "https://api-sandbox.lifeengine.io/translator/v1/public.key",
    "signatureValue": "ojh…wA8="
  }
}

Summary

As you can see fetching data production is very easy. All you need to know is application access token, product ID and parameters .

For detailed documentations on Platform of Trust core APIs, Visit Platform of Trust Broker API Documentation.

Ready to explore more?

Try Platform Sandbox

Improvement Suggestions? or a New Guide?

Tell us in GitHub