Create an API Based on the Slack Account
Task 1: Create a Slack Account with a Channel
Steps
Create a Slack account and create a workspace.
Email: _______________________________________________________
Field | Value |
---|
Workspace | newpurchaseorders |
Project | Training |
Login to https://slack.com/
On the home page, click on the Create Account button in the upper right corner.
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.
Click the Continue button. An e-mail will be sent to this eMail account with a verification code which you must then enter.
If the code was suitable, you are forced to create the workspace with the name newpurchaseorders
.
Click the Next button.
You can skip the next step. Click the Skip this step link.
In the next step, you can enter a project. For example: Training.
Click the Next button.
Skip the next step by pressing Skip this step.
You will then be asked if you want to continue working in the browser. Select this option and bookmark your workspace.
Click the Link Not now, continue in browser.
The home screen from your workspace:
Create a channel with name: notifications for your purchase order messages.
Use the following information:
Field | Value |
---|
Name | notifications |
Click on the Channels menu item. To the right of it appears a plus symbol when you move over with the mouse.
Click on the + - symbol, then choose Create a channel.
As Name enter notifications.
Click the Create button.
Skip the next step by pressing Skip for now.
The result:
Task 2: Create a Slack Instance
Steps
Create a Slack instance.
Navigate to SAP BTP Cockpit → Trial Subaccount → Services → Instances and Subscriptions.
Select Integration Suite.
Select the Extend Non-SAP Connectivity(Open Connectors) tile.
Bookmark this link.
Choose Instances in the left navigation bar and choose the Create Instance button on the right.
Search for Slack in the search area. Select the Slack icon.
On the next screen, enter newpurchaseorders in the name area (this is the Slack workspace name created earlier).
Select the OAuth Scope field. Add: chat:write, into the first position.
Do not forget the comma after the token chat:write.
Select the Create Instance button.
You will be redirected to Slack and automatically authenticated.
NoteAutomatic 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.
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
Test the Slack instance.
Choose Test in the API docs.
Find the GET endpoint /channels. Select Try it out.
Select Execute. Now you retrieve all the available channels of your newpurchaseorders workspace.
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.
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.
Find the POST endpoint with the following path: /channels/{channelId}/messages.
Click on the Try it out button.
At No. 1 : fill in your notifications channel Id from the last step.
At No 2: Scroll down and set My Textin the last field with name text
At No. 3: Click on the Excecute button.
You should get a HTTP code 200
:
Navigate to your Slack notifications channel and check out your notification channel if the message is posted.
Task 4: Create an API Proxy
Steps
Create an API proxy.
Select the gear icon on the bottom left side within the SAP Integration Suite - Open Connectors UI.
Store the Organization Secret and the User Secret in a place of your choice.
Open the API Management app from the SAP Integration Suite start screen. You start within the API Portal.
Select the Configure icon on the left side and then select the Create button.
In the Add API Provider screen, start with the Overview tab. Enter a meaningful name, for example, Slack_Workspace_for_Orders.
Switch to the Connection tab.
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
Enter the Organization Secret and User Secret from the Open Connectors Slack instance. These were stored in a previous step.
No entries are required in the Catalog Service Settings tab. Therefore, select the Save button.
The result should look like the following:
Navigate to the Develop area by selecting the development icon on the left. Choose Create.
Within the Create API dialog box, select the API Provider radio button and select your API Provider Slack_Workspace_for_Orders from the dropdown.
To pre-fill other entries, select Discover afterwards.
Choose your Open Connector instance, for example, newpurchaseorders and choose OK.
Enter a version, for example, v1.
The result should look like the following:
Select Create.
On the next screen, select Save.
Select the Development icon on the left again.
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.
After your API has been deployed, you will see the Deployed entry in the Status column.
Task 5: Test the API Proxy
Steps
Test the API proxy.
Select the Test icon in the navigational bar on the left side.
Choose your API, for example, Slack_v1.
Select the GET radio button.
Choose the /v1/Slack/channels URL from the listbox.
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
Create a product from your API.
Navigate to the start screen of the API Portal by selecting the Home icon in the navigational bar on the left.
Select the Product icon.
In the Overview tab, enter the following data:
- Name: supplier_slack
- Title : Supplier Slack
- Quota: 10000
- Requests Every: 1 ; Month(s)
Switch to the APIs(0) tab and select the Add button. Then select the Slack_v1 API flag and choose OK.
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.
You do not need other entries. Select Publish on top of the page.
After publishing, the status of your Slack API has switched to Published.
Check your work on the home screen of the API Portal. Select the Home icon in the navigational bar on the left.
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.