Import links as resources to 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 SAP 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:
- Python
- pandas library for Python
- LeanIX Data Interchange Format (LDIF) of the Integration API
- Inbound processors of the Integration API
- Fact Sheets in SAP LeanIX
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:
- By using the GraphQL API. For more information, see Retrieving Fact Sheets of a Specific Type.
- By exporting data in XLSX format in the application UI. To learn more, see Export Your Data via Excel. Once you've downloaded the file, convert it into CSV format.
Here's an example CSV file with the required columns.
type | id | name | url |
---|---|---|---|
Application | 28fe4aa2-6e46-41a1-....-72afb3acf256 | Technical documentation | https://docs.example.net/ |
Application | 2efa37b5-18aa-48d8-....-1328c0d856d7 | Vendor's website | https://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:
- In the administration area of SAP LeanIX, select Integration API.
- Click New Processor Configuration.
- 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.
- Click Create.
A processor is created.
Step 4: Complete a Processor Run to Import Data
Follow these steps:
-
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": {} }
-
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 thetype
andid
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/" } } ] }
-
Click Save.
-
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.
-
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.