Integrating our systems with third-party platforms like GitHub has become a common requirement in today’s business landscape, especially when working with public repositories that store documentation and configuration files.
In this blog post, I’ll walk you through how to connect SAP Open Connectors for GitHub with SAP Cloud Integration (CPI) to fetch a file from a GitHub repository and decode its contents. We’ll use SAP Open Connectors to securely access GitHub resources and apply a Groovy script in CPI to decode the Base64-encoded file content, helping you build a simple and reliable end-to-end integration.
By the end of this blog, you’ll have a clear understanding of how to:
1. Set up a GitHub instance in SAP Open Connectors
2.Connect SAP Open Connectors with SAP Cloud Integration (CPI)
Step 1: Fetching and decoding file content using Groovy scripting
To begin, you first need to create a GitHub instance in SAP Open Connectors. Start by logging in to the SAP BTP Cockpit and navigating to the SAP Open Connectors dashboard. This is where you’ll configure and manage your GitHub connection before using it in SAP Cloud Integration.
Next, enter your GitHub details. Provide your GitHub account name and the repository name. Make sure the repository you choose is public, as this is required for access without additional authentication
Once the details are filled in, click Create Instance. This will open the configuration screen where you can complete the setup for your GitHub instance.
Step 2: Testing GitHub APIs using Interactive API Docs
Before connecting everything to SAP Cloud Integration, it’s a good practice to test the GitHub connector using the Interactive API Docs provided by SAP Open Connectors. This helps confirm that your GitHub instance is correctly configured and able to retrieve data from your repository.
To do this, open the GitHub instance you just created from the SAP Open Connectors dashboard and navigate to the Interactive API Docs section.
Here, you’ll need to provide the required parameter, such as the file path within the repository (for example, /notes.md). After submitting the request, you’ll receive a JSON response.
After submitting the request, you’ll receive a JSON response. One of the key fields in this response is the content field, which contains the file data encoded in Base64 format.
This confirms that your GitHub instance is set up correctly and is able to access files from the specified public repository. In the next steps, this Base64-encoded content will be decoded in SAP Cloud Integration (CPI) using a Groovy script.
Step 3: Storing Open Connectors Credentials in Security Material
Before using SAP Open Connectors in your iFlow, you need to store the required credentials in SAP Integration Suite.
Step 4: Connecting SAP Cloud Integration (CPI) to GitHub using Open Connectors
Once your GitHub instance is set up and running, the next step is to connect it with SAP Cloud Integration so you can retrieve file content from the repository.
To do this, start by creating a new iFlow in your CPI workspace. Add a Sender step, such as a Timer or HTTPS adapter, based on how you want to trigger the flow. Then, add a Receiver step.
For the Receiver, choose the Open Connectors adapter from the list of available adapters. This adapter will be used to connect CPI with GitHub through SAP Open Connectors.
Deploy the iFlow and trigger it to run. This will call the GitHub API and fetch the file content, which is returned in a Base64-encoded format.
Once the file content is successfully retrieved from GitHub, you’ll see a response similar to the one shown below.
Step 5: Fetching and decoding the file content
At this stage, the file content fetched from GitHub is still in Base64 format, which isn’t readable. To convert it into plain text, you can use a Groovy Script step in your iFlow.
Add a Script step and use the following Groovy code to decode the content:
import com.sap.gateway.ip.core.customdev.util.Message
import java.util.Base64
def Message processData(Message message) {
def body = message.getBody(String)
def json = new groovy.json.JsonSlurper().parseText(body)
def encodedContent = json.content
def decodedBytes = Base64.decoder.decode(encodedContent)
def plainText = new String(decodedBytes, "UTF-8")
message.setBody(plainText)
return message
}
This script reads the Base64-encoded content from the API response, decodes it, and replaces the message body with the decoded, human-readable text.
After the Groovy script runs successfully, the file content appears as plain text, making it easy to read and use in further processing steps.
Conclusion :
In this blog, we explored how to connect to a public GitHub repository, retrieve file content, and decode it using Groovy scripting in CPI. In the next blog, we’ll take this a step further and look at how to work with private repositories using authentication tokens.
If you have any questions or would like a downloadable iFlow sample, feel free to drop a comment.