Technical Articles
Cloud Foundry API Portal and CPI API using an On Premise Odata Service
When The Neo Platform was disbanded and the cloud foundry combined CPI,API and others into integration suite – in the trial version there were issues with on Premise and I could not find much help to resolve this. It appears that some of these issues have been resolved. To explore this I decided to write a blog that demonstrates end to end the process where we connect the cloud connector to On Premise ECC, Create an API using API portal that queries an Odata Service and then Create Cloud Platform Integration that invokes the API and sends the output to email. Finally we expose the CPI integration flow as an API and invoke from Postman,
What we would like to accomplish in this blog in outlined in the diagram below.
Outline for this blog
Step 1) Configure the Cloud Connector – There are a number of blogs on this you can google this or look at the following blog
https://blogs.sap.com/2020/02/24/sap-cloud-connector-how-to-connect-an-abap-system-with-sap-cloud-platform/
Assuming that you have a cloud connector working – we have to create a cloud to on Premise connection for your cloud account.
1A) Log into Cloud connector as Administrator and Create a connection to your cloud subaccount by clicking on Add Subaccount button and enter the information as shown below and Save.
Cloud Foundry Subaccount Connection
1B) Create Cloud to on Premise Connection and Resources Access Paths – For the connection you created in Step 1 click on cloud to on Premise connection and the Plus(+) symbol to add and then create a resource Path as shown below
Cloud to On Premise Connection
Set the Required Resource Path on your On Premise System
Check the Connection and resolve any errors. If need be look the cloud connector logs and resolve the issue to complete this step.
Step 2) Using the Cloud Foundry API expose an On Premise OData Service as an API
It is assumed that you have a cloud foundry trial account and have subscribed to Integration Suite and created an instance of CPI and saved the Instance Keys in a local file. You can also look at my earlier blog
https://blogs.sap.com/2020/07/16/integration-suite-process-integration-sap-odata-with-splitter-gather/
A) Go the Integration Suite Subscription and click on the Go to Application and then Click on API management
Integration Suite Subscription API Management
B) in The API portal Click on Configure to configure ECC Source Connection
Configure a New Source
B2) There are 3 tabs in the Create Screen in the Description enter your information – The information in the Connection tab and Catalog Service Tab are as shown below
on Premise Connection and Catalog information
B3) On the top right hand side Click on Save and then to make sure that the connection is working Click on Test Connection. If you get errors you can check the logs in the Cloud Connector.
Test The Connection and Make sure you get 200 OK
Step 3) Expose On Premise Odata Service as an API. I have choosen EPM_REF_APPS_PROD_MAN_SRV odata Service to be exposed as an API using Cloud Foundry API management Portal.
3A) Click on Develop Icon on the left and choose Create and Enter the Following – Select API provide and from the dropdown choose the one Created in the previous Step. Click Discover and choose EPM_REF_APPS_PROD_MAN_SRV. Click Create to Save this.
Create an API From on Premise Data Source
Dont forget to Save and Deploy the API.
3B) Now go the Resources Tab and Select Products Get and Click on Try out – You will get an authentication error. To Correct this we need to Create Preflow Policies and update the API. To do this click on Policies on the top right hand side and choose Edit.
In the Policies screen on the left hand side click on Target End Point and Pre Flow Polices and on the right hand side click on Assign Message under Medication Policies and Click on + Symbol to Create a new Assign message Policy for the preflow. Give it a name and make sure that contents are as follows
<!– This policy can be used to create or modify the standard HTTP request and response messages –>
<AssignMessage async=”false” continueOnError=”false” enabled=”true” xmlns=’http://www.sap.com/apimgmt’>
<AssignVariable>
<Name>sapapim.user</Name>
<Value>On Premise User Name</Value>
</AssignVariable>
<AssignVariable>
<Name>sapapim.pass</Name>
<Value>on Premise ECC password</Value>
</AssignVariable>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew=”false” type=”request”>request</AssignTo>
</AssignMessage>
Next policy for the preflow is Basic Authentication under the security section on the right hand Side. Click the + symbol – Give it a name and enter the following in the main section
<BasicAuthentication async=’true’ continueOnError=’false’ enabled=’true’ xmlns=’http://www.sap.com/apimgmt’>
<!– Operation can be Encode or Decode –>
<Operation>Encode</Operation>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<User ref=’sapapim.user’></User>
<Password ref=’sapapim.pass’></Password>
<Source>request.header.Authorization</Source>
<AssignTo createNew=”false”>request.header.Authorization</AssignTo>
</BasicAuthentication>
This will ensure that the Caller of the API need not provide the user name and Password. If you want that the user should provide in the header then you can do that as well. You have to read from the request header in the above instead of reading from the assigned message.
Click on Update on the Right hand side and Do not forget to Save on the API screen. Please note that API is already deployed and after saving the above policies will be enforced.
3C) Test the API by clicking on the URL or you go Resources tab and choose on an entity set such as product and Select Get and Try out.
Test the API by Clicking on the URL
We are now move into Cloud Platform Integration and start to create a new integration flow that invoke the API that we created in Step 3.
3D) As mentioned earlier we going create an IFlow that will invoke the API and send the output to an email account. For this I have decided to choose gmail.To do this we need to configure gmail and CPI as described in the following blog.
https://blogs.sap.com/2020/12/06/cloud-platform-integration-gmail-configuration-and-integration-flow/
3E) Another thing we will do simplify testing is that we will create Trust configuration so that we can use email id and passport when using postman basic auth otherwise have to provide client id and client secret for the CPI instance in the dev space.
in the cloud Platform Main Screen Click on Roles and in the search box enter Message to check for a role Message Send as shown below’.
Role that links CPI instance with Message Send
Now Click on Role Collections and Create new Role Collection give it any name and assign this role MessageSend to the new collection. After the go to Trust Configuration on the left hand side and click on Default Identity provider. Enter your email id for the cloud foundry account and assign the role collection. This will enable to use your email id and password in postman instead of using client id and client secret of the CPI instance.
3F) Create an integration Package and add an artifact. Click the artifact and Json to XML converter, content modifier, External Call and Recover connected by Odata V2 and another receiver with email. Some these steps and configurations for these are as shown below.
3G) Create a new Artifact
Create a new Artifact in an integration Package and Click OK
3I) Select the package that was created and choose Edit. Then connect the Sender and Start icon and choose HTTPS and enter the configuration as shown below
Connect sender and Start with HTTPS and give it a name
3J) Drop in Json to XML converter as we would like to invoke an ODATA Service and then add Content Modifier – Create header and provide the header information as shown to store a variable productIdentifier which is of type java.lang.String and points to an Xpath //productIdentifier
Add Converter and Modifier and Create Header variable
3K) Add an External call – Request Reply and Receiver and connect them Choose Odata V2 and Configure the connection so that API created in Step 3 is invoked. The url for the API was
https://64dc9c38trial-trial.integrationsuitetrial-apim.eu10.hana.ondemand.com/64dc9c38trial/EPM_REF_APPS_PROD_MAN_SRV
3L) Add the Request Reply and Receiver and connect them using odata V2. For the odata url enter the url given in the previous step in the connection tab and in the processing tab choose select and choose Products Enttity in Step 2 and choose to filter by id where id =${header.productIdentifier} as the shown in the images below
Create Request Reply Receiver and Odata Connection
Choose Select from processing tab and select products
Choose Step 3 and enter filter condition.
When all configuration for odata has been done the result will be as follows
3M) Now the final Step in the IFLOW is to connect the End to Receiver and choose Email.
Configure the tabs for email connection
Finally Save and deploy the I flow. You can go the operations tab and make sure that Integration has started and note the url,
Operations View of CPI note the URL for Integration
3N) Use Postman to test the CPI integration.
Start postman and choose POST and enter the url that you copied from the previous step and choose basic Authentication – Enter cloud Foundry email id and password and click Send to run the integration that invokes API that calls on Premise Odata service thru the cloud connector and sends to an email account.
Postman output
Email received from CPI integration
4) Now we will Expose the CPI as API – You might be wondering why the need for this as we can invoke the CPI URL directly – The reason for this in real file APIs are packaged into products and Applications and the usage monitored and metered.
4A) We go to the API Management Portal and use quick links API from the home page and choose url from the options and enter
https://64dc9c38trial.it-cpitrial02-rt.cfapps.eu10-001.hana.ondemand.com/http/cpiapitest
do not enter /products as this will be added in the resources./cpiapitest iis the base path
Enter the information shown and select Create
4B) Go to the Resources Tab and choose add and enter the following information
Enter the /products Resource and Choose OK
Click Save and Deploy
4c) Choose the resources tab and selectProducts and POST method. Select Try out and in the body enter
{
“productIdentifier”: “HT-1000”
}
Choose Execute and you will get 401 error.
Click Copy on the Actions Options
The Policy Templates are copied into your Workspace. We need to apply these templates to the API we have created and enter the values for oauth from config file for CPI instance we are using to make this error go away.
4E) In the API portal Develop option Select the API that we are using and click on Policies on the top right corner
Choose Policies Edit and them templates apply
Select the Template we copied from Discovery and choose Apply
4F) Still in the Policies screen on the left choose Target End Point and Preflow – Choose getCrendentials.
Enter Client id and Client Secret from the config file
4G) Choose getoauthtoken and replace the oauth url with the url in the CPI instance Config file
Replace oauth url from Config file
Choose Update and SAVE – Now we can test these policies by going to the resources tab – Choose products and POST – Enter in the body json like before and you will get 200 with the contents
Test from Resources POST Method for Products
5) Now we are ready to test the complete Development – Get the url from API Developer tab copy and paste in Postman – Choose Basic Auth give email and password for cloud foundry account. In the boyd of the request for POST enter
{
“productIdentifier”: “HT-1000”
}
Choose Send
Dont Forget to add /products to the copied url
Check your email to see the see final results
Thanks for sharing, good for start learn integration suite and its capabilities. Look for your further integration suite blogs.