Importing Resources to Fact Sheets

Import links as resources to your application fact sheets using the Integration API.

Overview

To store additional information on a Fact Sheet, you can add the following resources to it: links, files, diagrams, and logos. To learn how to work with Fact Sheet resources in the application UI, see Store Resources on Fact Sheets.

In this tutorial, you'll learn how to import links as resources to Application Fact Sheets in batch using the LeanIX Integration API.

By the end of this tutorial, you'll be able to:

  • Programmatically convert a CSV file into LDIF format using a Python script
  • Import links to Application Fact Sheets using an inbound processor of the Integration API

Prerequisites

This tutorial assumes you have basic knowledge of:

Step 1: Prepare Data

The Integration API supports the LDIF format for processing data. To import data, you should first convert it into this format. In this tutorial, we convert a CSV file into LDIF format using a Python script.

Prepare a CSV file with links that you want to import to Application Fact Sheets. The file should contain the following columns:

  • type: The type of the Fact Sheet. In this tutorial, we only import Application Fact Sheets.
  • id: The ID of the Fact Sheet.
  • name: The name of the link to be added to the Fact Sheet as a resource.
  • url: The link URL to be added to the Fact Sheet as a resource.

You can retrieve Application Fact Sheets and their IDs in the following ways:

Here's an example CSV file with the required columns.

typeidnameurl
Application28fe4aa2-6e46-41a1-....-72afb3acf256Technical documentationhttps://docs.example.net/
Application2efa37b5-18aa-48d8-....-1328c0d856d7Vendor's websitehttps://www.example-vendor.net/

📘

Note

You can import multiple links to a single Fact Sheet.

Step 2: Convert a CSV File into LDIF Format

Once you've prepared a CSV file, convert it into LDIF format that the Integration API can process. The script in this tutorial uses the pandas library, a Python tool for data analysis and manipulation.

The following script converts and maps data into LDIF format and returns an output JSON file named output.json.

Example script:

import pandas as pd
import json

df = pd.read_csv("LeanIX_Resources_Import_template.csv")

excelData = []

for index, row in df.iterrows():
    excelData.append({
        "type": row['type'],
        "id": row['id'],
        "data": {
            'name': row['name'],
            'url': row['url']
        }
    })

ldif = {
        "connectorType": "leanix",
        "connectorId": "leanix-pandasCSV",
        "connectorVersion": "1.0.0",
        "processingDirection": "inbound",
        "processingMode": "partial",
        "lxVersion": "1.0.0",
        "description": "LDIF Generated by PANDAS CSV data",
        "content": excelData}

print ("Writing output to output.json")
f = open("output.json", "w")
f.write(json.dumps(ldif, indent=2))
f.close()
print ("Done")

Example output:

{
   "connectorType": "leanix",
   "connectorId": "leanix-pandasCSV",
   "connectorVersion": "1.0.0",
   "processingDirection": "inbound",
   "processingMode": "partial",
   "lxVersion": "1.0.0",
   "description": "LDIF Generated by PANDAS CSV data",
   "content": [
      {
         "type": "Application",
         "id": "28fe4aa2-6e46-41a1-....-72afb3acf256",
         "data": {
            "name": "Technical documentation",
            "url": "https://docs.example.net/"
         }
      },
      {
         "type": "Application",
         "id": "2efa37b5-18aa-48d8-....-1328c0d856d7",
         "data": {
            "name": "Vendor's website",
            "url": "https://www.example-vendor.net/"
         }
      }
   ]
}

Step 3: Create an Inbound Data Processor

Now that you have data to be imported in the required LDIF format, you can create a data processor for the Integration API and complete a run to import links to Applications in batch.

The inboundDocument processor is used to create, update, and delete resources linked to Fact Sheets. To learn more about the processor, see Inbound Document.

To create a processor, follow these steps:

  1. In the administration area of LeanIX, select Integration API.
  2. Click New Processor Configuration.
  3. Enter parameters for the processor:
    • Connector Type: Enter a name for the connector type.
    • Connector Id: Enter an ID for the connector.
    • Connector Version: Enter 1.0.0.
    • Processing Direction: Select inbound.
    • Processing Mode: Select partial.
    • Integrated Tool: Select None.
  4. Click Create.

A processor is created.

Step 4: Complete a Processor Run to Import Data

Follow these steps:

  1. On the page of the processor that you created, enter the following code in the input field on the left:

    {
      "processors": [
          {
            "processorType": "inboundDocument",
            "processorName": "applicationResourceMapper",
            "processorDescription": "Processor to link applications to their relevant resources",
            "identifier": {
                "internal": "${content.id}"
            },
            "run": 0,
            "updates": [
                {
                  "key": {
                      "expr": "name"
                  },
                  "values": [
                      {
                        "expr": "${content.data.name}"
                      }
                  ]
                },
                {
                  "key": {
                      "expr": "url"
                  },
                  "values": [
                      {
                        "expr": "${content.data.url}"
                      }
                  ]
                }
            ],
            "enabled": true
          }
      ],
      "variables": {}
    }
    
  2. Under Input, enter the following code. In the content field, add an array of objects in JSON format that you retrieved in the previous step. Each object should contain the type and id of the Fact Sheet and the links to be added. In the example, we import two links to Application Fact Sheets.

    {
      "connectorType": "leanix",
      "connectorId": "leanix-pandasCSV",
      "connectorVersion": "1.0.0",
      "lxVersion": "1.0.0",
      "description": "LDIF Generated by PANDAS CSV data",
      "processingDirection": "inbound",
      "processingMode": "partial",
      "customFields": {},
      "content": [
          {
            "type": "Application",
            "id": "28fe4aa2-6e46-41a1-....-72afb3acf256",
            "data": {
                "name": "Technical documentation",
                "url": "https://docs.example.net/"
            }
          },
          {
            "type": "Application",
            "id": "2efa37b5-18aa-48d8-....-1328c0d856d7",
            "data": {
                "name": "Vendor's website",
                "url": "https://www.example-vendor.net/"
            }
          }
      ]
    }
    
  3. Click Save.

  4. To test the processor, click Test run. Once the run is completed, check the output log for possible errors. If the run is successful, proceed to the next step.

  5. To initiate the import process, click Run.

The links with associated names are added as resources to the specified Application Fact Sheets.

To verify that the import was successful, navigate to the Resources tab of a specific Fact Sheet. You can also run a GraphQL query in the GraphiQL tool to retrieve resources for a specific Fact Sheet.

Example query:

{
  factSheet(id: "{id}") {
    id
    name
    documents {
      edges {
        node {
          origin
          url
          name
        }
      }
    }
  }
}

Summary

In this tutorial, you learned how to:

  • Programmatically convert a CSV file into LDIF format using a Python script
  • Import links to Application Fact Sheets using an inbound processor of the Integration API

Related Information

You can import other data types programmatically through the Integration API following a similar process. To learn more, see Integration API.