If you have ever been asked how many iFlows sit on a tenant, or which API proxies belong to which product, you already know how it goes. You open the UI, click into one package at a time, and copy names into a spreadsheet by hand. It takes a while, and the list is out of date the moment someone adds a new flow. I got tired of doing this, so I wrote a couple of small scripts to do it for me.
There are two scripts. Each one reads a different part of SAP Integration Suite and writes the result straight into an Excel file. They use the standard public OData APIs with an OAuth client credential, so nothing is installed on the tenant. You run them from your own machine and you get a clean spreadsheet at the end.
Here is the one thing to keep straight while you read. There are two separate scripts for two separate jobs:
They look alike and run the same way, but they connect to different services in BTP and need different roles. To avoid any mix up, I have written each one as its own part below. The download link for both is at the end.
Script Reads from Output file Sheets you get
| cpi_inventory_export.py | Cloud Integration | CPI_Inventory.xlsx | Packages, iFlows |
| apim_inventory_export.py | API Management | APIM_Inventory.xlsx | API Proxies, Products |
The output is plain and easy to filter. The CPI file gives you one row per iFlow with its package name, so you can sort or pivot however you like. The APIM file gives you one row per proxy with the product it sits in, which is the view most people are really after.
A few things need to be in place. These are the same for both scripts.
python --versionIf you see a version number come back, you are good. If the command is not recognised, install Python from python.org and tick the option to add it to PATH during setup.
Both scripts also need two small Python libraries. You only install these once, and the same two work for both scripts.
python -m pip install requests openpyxlThis is the script that answers the question, what packages and iFlows do we have. It talks to the Process Integration Runtime service.
In your subaccount, open Service Marketplace and search for Process Integration Runtime. Open the tile and choose Create. On the Basic Info screen set these values:
Move to the Parameters step. In the Roles field select WorkspacePackagesRead and keep the grant type as Client Credentials. This role is what lets the script read your packages and iFlows. If you leave it out, the API later tells you it cannot find the entity set, which is a confusing error for what is really just a missing role. Choose Create.
Open the cpi-extract instance, go to Service Keys, and create one. Name it something like cpi-extract-key and leave the parameters box as the empty braces. Open the key in JSON view and copy these four values:
The Cloud Integration url usually has it-cpi in the host name and often ends with -rt. Make a mental note of that, because it is the easiest way to tell it apart from the API Management url in Part 2.
Open cpi_inventory_export.py in any editor. Near the top, paste your four values inside the quotes and save. Keep the quotes in place.
CLIENT_ID = "your clientid"
CLIENT_SECRET = "your clientsecret"
TOKEN_URL = "your tokenurl"
API_URL = "your url"Open a Command Prompt, move into the folder that holds the script, and run it.
cd "C:\path\to\your\folder"
python cpi_inventory_export.pyWhen it finishes you will see a line like Done. 12 packages exported to CPI_Inventory.xlsx. Open the file and you will find a Packages sheet and an iFlows sheet, sitting in the same folder as the script.
This is the script that answers the question, what API proxies do we have and which product is each one in. It talks to the API Management, API portal service, which is a different service from Part 1.
In your subaccount, open Service Marketplace and search for API Management, API portal. Take care to pick this tile and not the developer portal tile next to it. Open it and choose Create. On the Basic Info screen set these values:
Move to the Parameters step. Here the role is entered as JSON, not picked from a list. This is the step people most often miss, and skipping it is what leaves you with an empty service key later. Type the role, then choose Create.
{ "role": "APIPortal.Administrator" }Do not have the Administrator role? You do not need it for this. The Administrator role allows create, update, and delete, but this script only reads. If you cannot or should not use Administrator, use the read-only role instead:
{ "role": "APIPortal.Guest" }APIPortal.Guest gives read-only access to the API portal, which is all the script needs to list your proxies and products. It is also the safer choice if you are following least privilege, so if you are unsure, start with Guest. Whichever role you choose, it goes here on the Parameters step of the instance, not on the service key.
Open the api-extract instance, go to Service Keys, and create one. Name it something like api-extract-key and leave the parameters box as the empty braces. Open the key in JSON view and copy these four values:
The API Management url has the word apiportal in the host name. This is the biggest difference from Part 1. If you accidentally use the Cloud Integration host, the one with it-cpi, you will get a 404, so double check you copied the url from this key and not the CPI one.
Open apim_inventory_export.py in any editor. Near the top, paste your four values inside the quotes and save. Keep the quotes in place.
CLIENT_ID = "your clientId"
CLIENT_SECRET = "your clientSecret"
TOKEN_URL = "your tokenUrl"
API_URL = "your url"Open a Command Prompt, move into the folder that holds the script, and run it.
cd "C:\path\to\your\folder"
python apim_inventory_export.pyWhen it finishes you will see a line like Done. 1 proxies and 1 products exported to APIM_Inventory.xlsx. Open the file and you will find an API Proxies sheet and a Products sheet.
If you take away one thing from this blog, take away this table. It shows exactly where the two scripts differ, so you always know which value belongs to which script.
cpi_inventory_export.py apim_inventory_export.py
| Service in BTP | Process Integration Runtime | API Management, API portal |
| Plan | api | apiportal-apiaccess |
| Role | WorkspacePackagesRead | APIPortal.Administrator, or APIPortal.Guest for read-only |
| url contains | it-cpi | apiportal |
| Output file | CPI_Inventory.xlsx | APIM_Inventory.xlsx |
These are the problems you are most likely to hit, with the quick fix for each.
Both scripts are on GitHub with a short README. Download them here and follow along.
Download: cpi_inventory_export.py
Download: apim_inventory_export.py
If this saved you some clicking, drop a comment and tell me what you would like to see next. I am happy to extend the scripts, for example to add deployment status or the last changed date for each artifact..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 19 | |
| 18 | |
| 14 | |
| 12 | |
| 11 | |
| 11 | |
| 11 | |
| 9 | |
| 9 |