Export iFlow from SAP CPI integration suite

iFlow is an integration flow which is a graphical tool that helps you to configure integration scenarios. Engineers design the iFlows and test them in lower environments. to move them to higher environments. This blog explains how to extract iFlow from SAP CPI using APIs.

Below is the step-by-step process to get the above task done and for this, we have written a python code to automate the process.

Prerequisites:

  1. Active subscription for SAP cloud
  2. Enabled Integration Suite

The ReST APIs for the SAP is available at: https://api.sap.com/api/IntegrationContent/resource

Here, we will use the ReST API to extract artifacts from the SAP CPI package.

  • Prepare the URI for extracting the iFlow. The URI for the same is:

URI: https://<your SAP Instance id>.cfapps.us10-001.hana.ondemand.com/api/v1/IntegrationDesigntimeArtifacts(Id='<iFlow name to be extracted>’,Version='<version of iFlow>’)/$value

  • Generate an authorization token via Postman using SAP cloud login username and password and use the GET ReST API method against the URI as below.

Make a note of the authorization token from the headers which we will use in the next step.

  • Prepare the headers for the GET request
headers = {
            'authorization': "Basic ****************y5jb206U3JlZWphQDMx",
            'x-csrf-token': "fetch",
            'cache-control': "no-cache"
        }
X-CSRF-TOKEN is the request with fetch value that gets you the csrf token which we will use for import operation.
  • The iFlow file is attached as zip to the response to the request. Below is sample code to get the file from response.
response = requests.request("GET", url, headers=headers)
filename = get_filename(response.headers.get('Content-Disposition'))

The file is attached as zipping with the ‘Content-Disposition property’. The below function helps you to read the file from the above property.

def get_filename(cd):
     """
     Get filename from content-disposition
     """
     if not cd:
         return None
     fname = re.findall('filename=(.+)', cd)
     if len(fname) == 0:
         return None
     return fname[0]
  • Save the file to the system.
open(filename, 'wb').write(response.content) 

Hope the blog helps you.

Leave a comment

0 Shares
Share via
Copy link
Powered by Social Snap