Developing with SAP Integration Suite

Creating an API Based on Slack

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Create an API based on the Slack account

Create an API Based on the Slack Account: Exercise Overview

Scenario

The notification about a new Purchase Order is to be delivered via Slack. For technical reasons, access to Slack is to be encapsulated via the SAP Integration Suite - API management capability.

In this exercise, you will create an API based on an Open Connector instance.

Task Flow

In this exercise, you will perform the following tasks:

  • Create an instance of the Slack API using Open Connectors.
  • Use an API proxy in API Management to encapsulate the connection.

Prerequisites

Prerequisites are:

  • You have a running SAP BTP (trial).
  • You have successfully installed and configured the SAP Integration Suite.

Create an API Based on the Slack Account

Create an API Based on the Slack Account

Exercise

Create an API Based on the Slack Account

Start Exercise

Task 1: Create a Slack Account with a Channel

Steps

  1. Create a Slack account and create a workspace.

    Email: _______________________________________________________

    FieldValue
    Workspacenewpurchaseorders
    ProjectTraining
    1. Login to https://slack.com/

    2. On the home page, click on the Create Account button in the upper right corner.

    3. Enter an eMail address.

      Use an eMail address, you have access to.

      Make sure, to take note of the e-mail you used in the Slack sign-up process into the line above.

    4. Click the Continue button. An e-mail will be sent to this eMail account with a verification code which you must then enter.

    5. If the code was suitable, you are forced to create the workspace with the name newpurchaseorders.

    6. Click the Next button.

    7. You can skip the next step. Click the Skip this step link.

    8. In the next step, you can enter a project. For example: Training.

    9. Click the Next button.

    10. Skip the next step by pressing Skip this step.

    11. You will then be asked if you want to continue working in the browser. Select this option and bookmark your workspace.

    12. Click the Link Not now, continue in browser.

    13. The home screen from your workspace:

  2. Create a channel with name: notifications for your purchase order messages.

    Use the following information:

    FieldValue
    Namenotifications

    1. Click on the Channels menu item. To the right of it appears a plus symbol when you move over with the mouse.

    2. Click on the + - symbol, then choose Create a channel.

    3. As Name enter notifications.

    4. Click the Create button.

    5. Skip the next step by pressing Skip for now.

    6. The result:

Task 2: Create a Slack Instance

Steps

  1. Create a Slack instance.

    1. Navigate to SAP BTP CockpitTrial SubaccountServicesInstances and Subscriptions.

    2. Select Integration Suite.

    3. Select the Extend Non-SAP Connectivity(Open Connectors) tile.

    4. Bookmark this link.

    5. Choose Instances in the left navigation bar and choose the Create Instance button on the right.

    6. Search for Slack in the search area. Select the Slack icon.

    7. On the next screen, enter newpurchaseorders in the name area (this is the Slack workspace name created earlier).

    8. Select the OAuth Scope field. Add: chat:write, into the first position.

      Do not forget the comma after the token chat:write.

    9. Select the Create Instance button.

    10. You will be redirected to Slack and automatically authenticated.

      Note
      Automatic authentication only works when you are using the same browser session that was used for the Slack login. Otherwise, login again with the credentials you used for Slack registration.
    11. Check if you are in the correct workspace and allow the access to Open Connectors by selecting Allow.

Task 3: Test the Slack Instance

Steps

  1. Test the Slack instance.

    1. Choose Test in the API docs.

    2. Find the GET endpoint /channels. Select Try it out.

    3. Select Execute. Now you retrieve all the available channels of your newpurchaseorders workspace.

    4. Find your newly created channel, notifications, in the response body. Find it by looking for the attribute name in the JSON. Store the regarding channel ID (*id*) in a place of your choice.

  2. Write a message to the notifications channel.

    Now we try to write a message to the notifications channel within your newpurcasheorders workspace to test if our additional OAuth scope parameter works.

    1. Find the POST endpoint with the following path: /channels/{channelId}/messages.

    2. Click on the Try it out button.

    3. At No. 1 : fill in your notifications channel Id from the last step.

    4. At No 2: Scroll down and set My Textin the last field with name text

    5. At No. 3: Click on the Excecute button.

    6. You should get a HTTP code 200:

    7. Navigate to your Slack notifications channel and check out your notification channel if the message is posted.

Task 4: Create an API Proxy

Steps

  1. Create an API proxy.

    1. Select the gear icon on the bottom left side within the SAP Integration Suite - Open Connectors UI.

    2. Store the Organization Secret and the User Secret in a place of your choice.

    3. Open the API Management app from the SAP Integration Suite start screen. You start within the API Portal.

    4. Select the Configure icon on the left side and then select the Create button.

    5. In the Add API Provider screen, start with the Overview tab. Enter a meaningful name, for example, Slack_Workspace_for_Orders.

    6. Switch to the Connection tab.

    7. Choose Open Connectors as Type. The following fields change accordingly. Enter the following data:

      • Region: the region of your trial account
      • Host: pre-filled
      • Port: pre-filled
    8. Enter the Organization Secret and User Secret from the Open Connectors Slack instance. These were stored in a previous step.

    9. No entries are required in the Catalog Service Settings tab. Therefore, select the Save button.

    10. The result should look like the following:

    11. Navigate to the Develop area by selecting the development icon on the left. Choose Create.

    12. Within the Create API dialog box, select the API Provider radio button and select your API Provider Slack_Workspace_for_Orders from the dropdown.

    13. To pre-fill other entries, select Discover afterwards.

    14. Choose your Open Connector instance, for example, newpurchaseorders and choose OK.

    15. Enter a version, for example, v1.

    16. The result should look like the following:

    17. Select Create.

    18. On the next screen, select Save.

    19. Select the Development icon on the left again.

    20. Open the action dropdown dialog by selecting the Action icon in the most right column of your Slack API entry. In the dialog box, select Deploy.

    21. After your API has been deployed, you will see the Deployed entry in the Status column.

Task 5: Test the API Proxy

Steps

  1. Test the API proxy.

    1. Select the Test icon in the navigational bar on the left side.

    2. Choose your API, for example, Slack_v1.

    3. Select the GET radio button.

    4. Choose the /v1/Slack/channels URL from the listbox.

    5. Now, choose Send at the bottom of the page. If everything works, you will see the Response Body with all available channels of your Slack workspace that you used within the Open Connector instance.

Task 6: Create a Product From Your API

Steps

  1. Create a product from your API.

    1. Navigate to the start screen of the API Portal by selecting the Home icon in the navigational bar on the left.

    2. Select the Product icon.

    3. In the Overview tab, enter the following data:

      • Name: supplier_slack
      • Title : Supplier Slack
      • Quota: 10000
      • Requests Every: 1 ; Month(s)
    4. Switch to the APIs(0) tab and select the Add button. Then select the Slack_v1 API flag and choose OK.

    5. Select the menu on the top right of the screen and select API Business Hub Enterprise. Then go back to API Portal and perform the next substep.

      Before you can publish, make sure that you have opened the API Business Hub Enterprise feature within the API Management capability at least once. This is required, because after activating the capability, some further setup steps need to be carried out. They will only be processed once you access the application.

    6. You do not need other entries. Select Publish on top of the page.

    7. After publishing, the status of your Slack API has switched to Published.

    8. Check your work on the home screen of the API Portal. Select the Home icon in the navigational bar on the left.

      Summary:

      In this exercise, you have used Open Connectors to create an instance of Slack.

      In SAP API Management, you encapsulate this connection to the outside world with an API proxy.

      In the next exercise, we will make the created API available in an API Business Hub Enterprise page.

Save progress to your learning plan by logging in or creating an account