Example: Multicontext with an API Gateway
This example shows how a multi-context flow can be produced from requests in an API Gateway. Data included in the request is used to inform the contexts.
Flow Definition
Through a REST call set up in Integra's API Gateway, this integration aims to make weather data kept in a Postgres database accessible. The database created by Example Integration: Multicontext with Time Trigger will serve as our starting point.
This integration will initially only be able to access one database for a single user. Then the same integration will be expanded so that multiple users can access it by simply entering their userid. This will be the data we use to identify the context and with this Integra.Sky can access the correct database for each user.

Steps
Step by Step
Step 01: Create the original monocontext flow
This flow is triggered by a request through the API Gateway. The request must include in the query string only the number of most recent samples to be retrieved from the database. The response contains the samples along with some average temperature and humidity data, which are calculated by Skyone Studio itself.

Call to trigger the flow:
https://myspace.apihml.integrasky.cloud/eZB6Hf/weather/v1/mylocation?n=100
The user database's most recent 100 records are retrieved as a result of this call. Along with these statistics, the average temperature and humidity are also returned.
Step 02: Insert the variable that will define the context
In this case, we will use a piece of information that comes in the API call itself to define what the context will be. To do this, we will change the Query String of the Trigger API to make it ready to accept the userid. This will be the variable used to define the context. Each userid will link to a particular database account.

With this modification, we will use external information to define the context that will be used.
Step 03: Insert the Context Finder
"Context Finder" will use the context set variable (userid) to locate the database account that will be used to retrieve the weather records.
Context Finder should be inserted right after the API trigger so that it can use the information that comes in the trigger call to identify the context.

And we will indicate the userid information, which is inside the query string, as a context identification parameter.

Step 04: Update the Postgres module to use the access accounts according to the Context
Go back to the Postgres module configuration and enable the "Use context in this component" option.
By default, Skyone Studio will use the account previously configured as the Default account.

You must click "Next". Select the context and run a test of the new configuration. Since you have already executed this flow in single-context mode, Skyone Studio will use the original account as the default account.

Step 05: Set up Database access accounts
Each of the contexts should have its own specific account associated with it.
Create the database accounts in Settings → Connected Accounts.

Step 06: Create the contexts
Create a context for each user that will access the system.
Select "Context" from the flow editing page. Add as many contexts as needed, and specify the value of the key associated with each context.

Step 07: Link the accounts with the contexts
For each of the contexts, link the respective Postgres module account.
In Flow Context, edit each of the contexts. Select the Connected Accounts tab and select the respective account.
Step 08: Call the flow with context information
Enter the userid in the API call that calls the flow.
In your API calling software, specify the value of the userid. Use one of the values specified when creating the context.
https://myspace.apihml.integrasky.cloud/eZB6Hf/weather/v1/mylocation?n=10&userid=0002
Notice that you are now provided with two values for the execution of the flow. The value of n specifies the number of samples that will be retrieved and the value of userid specifies the context and therefore which database will be chosen.
You can see that we can identify the correct operation of Context Finder by the execution logs.
Last updated