Using the SAP PI Directory API from Python
Overview
The SAP PI Integration Builder Directory exposes a SOAP API to programmatically access, edit, and activate configuration objects. You may want to use it to perform bulk changes, to update routing rules such as a receiver determination at runtime or possibly to automatically generate some documentation. The code below is an example of how to invoke an API service from Python.
h2. Getting the WSDLs
The service WSDLs are available in the Enterprise Service Repository (ESR) as external defintions under the software component version SAP BASIS 7.10 and the namespace http://sap.com/xi/XI/System. However, as is the case for ESR objects in general, the WSDLs are landscape agnostic, in other words details such as bindings are missing. You can either add these manually or, as I did below, dynamically load the WSDLs from the Webservice Navigator.
h2. Prerequisites
This demo uses the the Python SOAP client Suds available from https://fedorahosted.org/suds/ or the Python Cheese Shop. In addition your PI user requires the following roles:
- SAP_XI_API_DISPLAY_J2EE
Demo module
def demo():<br /> “”” <br /> Invoke the ‘query’ operation of the BusinessComponentService and print the<br /> response.<br /> “””<br /> <br /> # Enable logging to print SOAP request and response to console<br /> logging.basicConfig(level=logging.INFO)<br /> logging.getLogger(‘suds.client’).setLevel(logging.DEBUG)<br /> # Create client instance for BusinessComponentService<br /> client = getservice_client(‘BusinessComponentService’)
# Create empty request object – see print(client) for service & type info
request = client.factory.create(‘ns2:BusinessComponentQueryIn’)
# invoke the BusinessComponentService’s “query” operation
response = client.service.query(request)
print(response)
if __name__ == ‘__main__’:
_demo()h2. Resources
SAP Help – Integration Directory API
- [Suds Homepage | https://fedorahosted.org/suds/]
Thanks for the example!