Skip to Content
Technical Articles
Author's profile photo Ramesh Vodela

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%20for%20this%20blog.

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%20Foundry%20Subaccount%20Connection

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%20to%20On%20Premise%20Connection

Cloud to On Premise Connection

Set%20the%20Required%20Resource%20Path%20on%20your%20On%20Premise%20System

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%20Suite%20Subscription%20API%20Management

Integration Suite Subscription API Management

B)  in The API portal Click on Configure to configure ECC Source Connection

Configure%20a%20New%20Source

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%20Premise%20Connection%20and%20Catalog%20information

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%20The%20Connection%20and%20Make%20sure%20you%20get%20200%20OK

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%20an%20API%20From%20on%20Premise%20Data%20Source

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%20the%20API%20by%20Clicking%20on%20the%20URL

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%20that%20links%20CPI%20instance%20with%20Message%20Send

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%20a%20new%20Artifact%20in%20an%20integartion%20Pacakge

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%20sender%20and%20Start%20with%20HTTPS%20and%20give%20it%20a%20name

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%20Converter%20and%20Modifer%20and%20Create%20Header%20variable

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%20Request%20Reply%20Receiver%20and%20Odata%20Connection

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%20the%20tabs%20for%20email%20connectioin

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%20View%20of%20CPI%20note%20the%20URL%20for%20Integration

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%20output

Postman output

Email%20received%20from%20CPI%20integration

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%20the%20information%20shown%20and%20select%20Create

Enter the information shown and select Create

 

4B) Go to the Resources Tab and choose add and enter the following information

Enter%20the%20/products%20Resource%20and%20Choose%20OK

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.

 

4D) To Correct this errors we need to apply API Policy Templates – For this we can use SAP provided Policy templates by  going to the discover API tab and enter Connect to SAP Cloud Platform services.  Click%20Copy%20on%20the%20Actions%20Options

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%20Policies%20Edit%20and%20them%20templates%20apply

Choose Policies Edit and them templates apply

Select%20the%20Template%20we%20copied%20from%20Discovery%20and%20choose%20Apply%20and%20then%20Update%20and%20Save%20the%20API

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%20Client%20id%20and%20Client%20Secret%20from%20the%20config%20file

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%20oauth%20url%20from%20Config%20file

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%20from%20Resources%20POST%20Method%20for%20Products

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%20Forget%20to%20add%20/products%20to%20the%20copied%20url

Dont Forget to add /products to the copied url

 

Check your email to see the see final results

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Frank Li
      Frank Li

      Thanks for sharing, good for start learn integration suite and its capabilities. Look for your further integration suite blogs.