Technical Articles
SAP Cloud Platform: Connect to Facebook using open connector
SAP recently launched open connectors which empowers SAP system to connect with third party systems without complex coding or custom modules. The aim of the connectors is to simplify the integration by providing connectors for SAP & Non-SAP applications. It comes with 150 pre-built connectors and connectors can be developed based on integration requirement as well.
As the landscape is getting complex for customers,with new systems coming in to picture,Integration plays an important role for any client.Cloud platform open connectors work on RESTFUL API calls and these API’s can be easily used for 3rd party integration.
In this blog, I will explain how to use Facebook connector. This connector may not be used as real time use case but the aim of the blog is to explain the required setup and basic setup connectivity for open connectors using SAP cloud platform. We will cover below topics in this blog.
- SAP Cloud platform trial account setup (NEO)
- Facebook connectivity with cloud connector
- Test Using Facebook connector in SAP API hub
SAP Cloud platform trial account setup:
- Open URL https://account.hanatrial.ondemand.com and register for trial version.
2. Choose Neo trial and click on services on left hand side bar.
3. Search for ‘open connector’ service and click on enable.
4. Once enabled, select ‘Go to Service’ in ‘Take action’ option which is available in bottom.
5. Activate ‘API management’ service as well. We will use this service to test the connector with API.
- Facebook connectivity with open connector:
1.Go to cloud connector service and click on ‘Connectors’ to view the pre built connectors. Search for ‘Facebook Connector’. Hover the mouse over Facebook connector and click on Authenticate.
2.Click on ‘Authenticate instance’ and create your instance. Create it with any name and choose authentication type as ‘OAUTH2’. With the default authentication oauth2, you will receive a pop up for login to facebook. once logged in, it will generate the instance. This will also generate user parameters .
3. Click on Test in API docs.
4. Under resources option, you will see multiple options to connect to facebook and fetch the data. Based on the options, user data(profile info,status,comments,page info etc) can be retrieved. These options can be customized by creating new end points.For example, it can be customized to post status or photo to your facebook profile.
5.There are various options available for each connector and can be used directly based on the requirement. We will try to fetch all status posted by particular user by calling ‘status’ end point. Click on ‘status’ and select ‘try it out’. Authorization will be mandatory but as we selected oauth2 authorization during instance generation, Authentication token is already generated for this test.
6. Click on execute and you should receive the response 200. This will fetch all the status with creation date and time. Page string and size can be added to the query as well.
7. You will get CURL command with REST API details which will contain authentication token. Save the parameters for further testing via API’s.
- Test Using Facebook connector in SAP API hub
1.Let’s test Facebook connector with SAP API’s. Go to API management service and click on ‘Access API portal’. Click on pencil option on the left side menu and create new API proxy with below parameters.
URL: https://api.openconnectors.ext.hanatrial.ondemand.com/elements/api-v2/status
API Base Path: /elements/api-v2/status
API Provider: None
2. In the API call, we will have to pass the authorization parameters. We will use policies to update the call. Click on Policies, select preflow and add ‘AssignMessage’ policies from meditation policies. Give any name and save it.
3. Update the policy with below header parameter. This parameter will authorize the connection to facebook. We will use the authentication token from Curl command. Paste below tag in <set> node of policy.
<Headers>
<Header name=”Authorization”>User XXX=, Organization YYY, Element ZZZ=</Header>
</Headers>
4. Save and deploy it.
5. Go to test console and search for your API.. Make sure you remove SWAGGER_JSON from URL. Click on Send and it should fetch the status as response.
6. You can add additional parameter for customizing the query.
We can test various open connectors with above approach. We can also create our own connector end point to achieve specific functionality. With API portal, we can use QUOTA, CACHE, JSON threat protection or any other policy to test various API functionalities.
Happy Learning.
Related Content:
API Management: https://open.sap.com/courses/cp8
Integration with open connector: https://blogs.sap.com/2018/09/19/part-2-connect-to-a-third-party-cloud-applications-via-sap-cloud-platform-open-connectors/