Testing

To test your application locally, demo user context can be used to observe functionality. The platform-api.js function getPlatformContext cannot be used outside of the platform scope, you can test the application with platform context by contacting our team and receiving access to a demo customer portal for this purpose.

// Demo user context to test functionality locally.
{
    "auth_token": "eb837c91-bee4-4011-8af5-1f7af649be92",
    "euser": "heera@xeiex.com",
    "plant_selected": "1",
    "language_selected": "en",
    "plant_list": [
        {
            "plantId": 2,
            "plantName": "Kilsyth",
            "plantCode": "5698",
            "defaultPlant": false
        },
        {
            "plantId": 1,
            "plantName": "Brisbane 01",
            "plantCode": "0987",
            "defaultPlant": true
        }
    ],
    "company_code": "1234",
    "roles": [
        "GRP_M_ADD",
        "TOOL_CRD_VIEW",
        "SOP_A_VIEW",
        "TSOP_M_ADD",
        "QSOP_IU_DEL",
        "OPR_ACT_ADD",
        "VENDOR_M_EDIT",
        "PROC_TYP_M_DEL",
        "QSOP_V_VIEW",
        "COM_M_EDIT",
        "DTC_EDIT",
        "8e08d9_Add_VIEW",
        "MACH_M_EDIT",
        "SOP_M_ADD",
        "QC_VIEW"
    ]
}

App (Client Token)

As mentioned in 'Accessing Masterdata', both an application token (client token) and a user token (auth_token) are required to be able to utilise AAS and Submodel data. A demonstration of retrieving the Application token is demonstrated below.

"""
Python Sample Code, retrieving App token, this must be either refreshed
automatically every 30 seconds by scheduling execution in app or by 
requesting a new token.
"""
def get_access_token():
    INDUSTRY_API_URL = 'https://auth.uat.industryapps.net/auth/realms/IndustryApps/protocol/openid-connect/token'
    headers = {'content-type': 'application/x-www-form-urlencoded'}
    body = {
        "grant_type": "client_credentials",
        "client_id": "<<App ID>>",
        "client_secret": "<<App Secret Code>>"
    }
    token = requests.post(INDUSTRY_API_URL, data=body, headers=headers)
    token_response_data = token
    try:
        access_token = token_response_data['access_token']
        return access_token
    except:
        return token_response_data

As a reminder, the App ID and App Secret Code are available by navigating onto your app dashboard > App Information:

Note that the access token will not be available outside the demo customer portal or platform scope, resulting in an invalid token response while hosting the application externally.

Once the application has access to its app and user context token, integrating Masterdata or Transactional data from the platform to test and implement functionality is worked through calling the available endpoints.

# Fetching AAS List from the platform.
def get_aas_list(asset_type, plantcode):
    # App Token Generation
    access_token = get_access_token()
    # Retrieving stored user context from temporary Redis Cache
    user_context = rs.get("user_information")
    extract_user = json.loads(user_context)
    user_token = extract_user["auth_token"]
    # Required Tokens for a successful response.
    headers = {
        "Authorization": 'Bearer ' + access_token,
        "UserToken": 'Bearer ' + user_token
    }
    # Set Asset Type & Plant Code in func params
    params = {
        "AssetType": asset_type, 
        "PlantCode": plantcode
    }
    try:
        res = requests.get(AAS_LIST_URL, headers=headers, params=params)
        return res
    except Exception as e:
        print(e)

Platform context endpoints can be experienced by forking the IndustryApps Postman collection. The app and user tokens should be added in the environment of the forked collection.

Local & Production deployment

The application can be connected via the pre-defined sidecar, Eureka endpoints and have the container image pushed onto the platform. Once the app has been onboarded, user experience can be tested via a demo customer portal as part of the Vendor registration process. You will receive a trial user id and password for the developer store and smart factory platform.

Last updated