Block Editor API Calls

      Block Editor API Calls


        Article summary

        Creating a Data block for API Call data Interfacing.

        Below are the steps to use the API Call Block Type for data interfacing.

        1. Create a data block with Category as “Interface”, Block Type as “API Call” and the Output Type as provided from the source. For this example, the “Data Table” Output Type is selected.

        2. The provided templates can be opened to see the required parameters. There are 3 sample templates as shown below.

        2a. Basic HTTP: The Basic HTTP template type can be selected for basic HTTP calls. Ideally access to these API endpoints should be public for the Assette Application to access the endpoints.
        The following template is the general structure required.

        For example, if a public API endpoint is used, the structure maybe as follows.

        • baseUrl: This represents the base URL of the API you're interacting with. It consists of two placeholders <<domain>> and <<path>> which are expected to be replaced with the actual domain and path of the API endpoint respectively. For example, if the domain is "api.example.com" and the path is "/endpoint", the resulting URL would be "https://api.example.com/endpoint".

        • method: Specifies the HTTP method to be used when making requests to the API. In this case, it's set to "POST", indicating that the data will be sent to the server in the request body.

        • bodyTemplate: This represents a template for the request body. It's a JSON object with placeholders like {{p1}} which are expected to be replaced with actual values during runtime. For example, if {{p1}} is replaced with "value1", the resulting body would be {"param1":"AAA","param2":"value1"}. Can be removed as well if no parameters are being using.

        • jsonpath_for_data: Specifies the JSON path used to extract data from the response of the API. This JSON path should be formatted according to the JSONPath specification and will be used to extract specific data from the response payload, usually it is “$.response_data.data”.

        2b. Basic API: These are often configured by Assette. If any private API endpoints are available that can be utilized, it should be configured within Assette and the endpoint should be whitelisted for the Assette Application to use. A description of the parameters is as follows;

        • api_fowarder_key: The key name created by Assette for certain use cases.

        • method: We are using the "POST" method to send data to the API. Other common HTTPS methods can be used.

        • path: The path key is configured by Assette based on the API configuration. (optional)

        • queryTemplate: The API expects the parameter name to be passed as part of the path. (optional)

        • bodyTemplate: This represents a template for the request body. It's a JSON object with placeholders like {{p1}} which are expected to be replaced with actual values during runtime. For example, if {{p1}} is replaced with "value1", the resulting body would be {"param1":"AAA","param2":"value1"}.

        • jsonpath_for_data: We're specifying the JSON path to extract the current weather data from the API response. In this example, we're assuming the relevant data is located under “$.response_data.data”.

        2c. Return Columns Separately: This is a slight alteration to the Basic API type, with an extra parameter to output the column names.
        A screenshot of a computer program  Description automatically generated

        A description of the parameters is as follows.

        • api_fowarder_key: The key name created by Assette for certain use cases.

        • method: We are using the "POST" method to send data to the API. Other common HTTPS methods can be used.

        • path: The path key is configured by Assette. (optional)

        • queryTemplate: The API expects the parameter name to be passed as part of the path. (optional)

        • bodyTemplate: This represents a template for the request body. It's a JSON object with placeholders like {{p1}} which are expected to be replaced with actual values during runtime. For example, if {{p1}} is replaced with "value1", the resulting body would be {"param1":"AAA","param2":"value1"}.

        • jsonpath_for_data: We're specifying the JSON path to extract the current weather data from the API response. In this example, we're assuming the relevant data is located under $.response_data.data.

        • jsonpath_for_column_names: This likely represents the JSON path used to extract column names or headers from the response data. It's expected to return a list of column names. Usually the parameter can be filled as “$.response_data.columns”. (optional)

        3. Based on the requirements, any of the above templates can be used to extract data.

        Example 1 (API Configuration within Assette):

        A sample data block named “DEMO_API_HoldingsDetails”, is created to demonstrate the process.

        1. In the General Info tab define the Data Block settings and pick “API Call” as the Block Type.

        A screenshot of a computer  Description automatically generated

        2. Select a suitable template as per the requirements. For this example, the Basic API type template was selected, and the parameters were changed as required.

        {"api_fowarder_key": "Dynamicapi",

        "path": "/api/holdings/portfolioholdings",

        "method": "POST" ,

        "bodyTemplate": "{\"AccountCode\":\"{{AccountCode}}\",\"AsofDate\":\"{{AsofDate}}\",\"CurrencyCode\":\"{{CurrencyCode}}\",\"SectorScheme\":\"{{SectorScheme}}\"}",

        "jsonpath_for_data": "$"}

        A screenshot of a computer  Description automatically generated

        3. Save the data block and test it with the correct parameters required.

        A screenshot of a computer  Description automatically generated

        Example 2 (Connecting to a Public Endpoint).
        1. Use the Basic HTTPS template and change the parameters as needed.

        2. Once saved, test the block.
        A screenshot of a computer program  Description automatically generated