:::info BTP平台有時候加載較慢,會有UI延遲,或是資料沒有即時更新的情況。如果有時候有些按鈕沒有出現,或是狀態沒有更新,重新整理後有可能就好了。 ::: # Set Up Integration Suite Trial https://developers.sap.com/tutorials/cp-starter-isuite-onboard-subscribe.html ![image](https://hackmd.io/_uploads/BkCyGmCO0.png) :::warning **※有待補充** 建立帳號時的設定: | 欄位名稱 | 值 | |----------|--------------------------| | Provider | Amazon Web Services (AWS)| | Region | US East (VA) | 有段時間我的Integration Suite處於無法登入的狀態,推斷有可能是之前不小心將Space刪除掉的可能性,記得好像是在重新建立新的Space後,就可以用了。 ![image](https://hackmd.io/_uploads/Sy8O9E_90.png) 遇過另外一種情況是,Subaccount裡面沒有Cloud Integration的服務,可以到Service MarketPlace重新Create: ![image](https://hackmd.io/_uploads/BJtIBgoqA.png) ![image](https://hackmd.io/_uploads/ByvKrxj9R.png) ![image](https://hackmd.io/_uploads/HyjyUlo5R.png) 雖然原理不太清楚,但Integration Suite確實因此恢復了 :D **※ 補充** BTP的Global account分成Trail(試用)與Enterprise(企業)帳號,在User權限上,Trail已經將大多數的可用權限打包在User設定上,但Enterprise會分成GlobalAccount用的User,以及SubAccount用的User(IAS);在Trail,只要透過Booster就可以啟用Integration Suite的全部功能,而Enterprise需要在有IAS的用戶開啟全部權限後,Integration Suite的功能才能全部啟用。 ::: ## Step 1. Enter your trial account 1. 建立一個SAP Global Account,登入[SAP BTP Cockpit](https://account.hana.ondemand.com/#/home/welcome) 2. 點擊"**Go To Your Trail Account**" ![image](https://hackmd.io/_uploads/BJV5yBAdA.png) 3. 點擊已經建立好的Subaccount,名稱為Trail。 ![image](https://hackmd.io/_uploads/S1x-gS0OR.png) :::info **補充:如何建立一個Subaccount?** 1. 點擊右上角的Create,選擇Subaccount。 ![image](https://hackmd.io/_uploads/rkPJWIe5R.png) 2. 輸入Display Name、Region和Description,另外兩欄會自動輸入。然後按下Create。 ![image](https://hackmd.io/_uploads/r1-ibIl9C.png) 3. 等它跑一下就完成了。 ![image](https://hackmd.io/_uploads/HJ8KGLx5A.png) ::: ## Step 2. Subscribe to the service 1. 點擊左側的**Service -> Instances and Subscriptions**. 2. 點擊右上角"Create"後,輸入以下內容: | 欄位名稱 | 值 | |----------|--------------------------| | Service | Integration Suite| | Plan | trail | 3. 點擊左側欄位**Security > Users**,點擊進入**Default identity provider**,在右側的**Role Collections**,點擊三個圓點Icon後,選擇**Assign Role Collection** ![image](https://hackmd.io/_uploads/ryENNx0Y0.png) 4. 搜尋 Integration_Provisioner並勾選,然後按下 Assign Role Collection. ![image](https://hackmd.io/_uploads/B1_1nSRdR.png) 5. 回到**Service -> Instances and Subscriptions**,在Instance點擊Integration Suite,進入SAP Integration Suite平台,點擊**Add Capabilities**。 ![image](https://hackmd.io/_uploads/Byr4zxRKA.png) ## Step 3. Activate the capabilities 1. 勾選 **Build Integration Scenarios** 和 **Manage APIs capabilities**. 然後按下 Next. 2. 不用理會Cloud Integration,繼續按Next。 3. 勾選**Enable API Business Hub Enterprise**,然後按下Next。 4. 當出現這個畫面時,就代表完成了。 ![image](https://hackmd.io/_uploads/SJ7sHxRKC.png) ## Step 4. Automatically assign roles and create service instances using Booster 1. 回到Global Account,選擇Booster 2. 搜尋Enable Integration Suite並點進去 3. 點擊右上角的Start 4. 第一頁系統應該會自動填入,點擊Next;第二頁勾選 **Design, Develop, and Operate Integration Scenarios** 和 **Design, Develop, and Manage APIs**,點擊Next。 5. 按下Finish,等待系統設定完畢。 6. 回到SAP Indegration Suite平台,確認新加載的服務。 # Design and Deploy Your First Integration Flow https://developers.sap.com/tutorials/cp-starter-integration-cpi-design-iflow.html ## Step 1. Create an integration package and integration flow 1. 在左側欄選擇Design > Integrations and APIs > Create,建立一個integration package,按照欄位填入以下內容後,按下Save。 | 欄位名稱 | 值 | |----------|--------------------------| | Name | Indegration Suite Trail Experience | | Technical Name | Name輸入時會自動填入 | | Short Description | Indegration Suite Trail Experience | 2. 選擇 Artifacts 的區塊,在Add的下拉清單選擇Integration Flow,輸入Flow的名稱後,按下OK,然後再按下右上角的Save即可保存。 :::info 雲端平台具有保護設計, 在執行修改前,通常要先確認有按下右上角的"Edit",否則有些動作會無法執行。 修改完後,記得要按下Save才會保存。 ::: ![image](https://hackmd.io/_uploads/Hy5DqgAFA.png) 3. 點開 integration flow,點擊右上角Edit進行編輯,並點選右下角"Restore"按鈕將參數列表展開。 ![image](https://hackmd.io/_uploads/Skml2g0KR.png) ## Step 2. Connect sender channel with HTTPS adapter 將Sender的箭頭連接到Start,Adapter Type選擇"HTTPS"。在下方參數選項選擇"Connection"區塊,並填入對應的資料。 | Address | Authorization | User Role | | -------- | -------- | -------- | | /products/details | User Role | ESB Messaging.send | **最後,取消勾選CSRF。** :::info Address可以再需要進行辨識時,替換成其他自定義的字串,但開頭一定要是"/"。 ::: ## Step 3. Add JSON to XML converter 在上方的工具列選擇"Transformation"的圖示,選擇Converter、再選擇JSON to XML Converter,然後在Start與End之間的箭頭點一下,就建立了Json to XML的轉換器。 ![image](https://hackmd.io/_uploads/rJLLW-AtA.png) ## Step 4. Add and configure content modifier 在上方的工具列選擇"Transformation"的圖示,選擇Content Modifier,在Start與End之間的箭頭,JSON to XML Converter的右邊點擊建立。並在下方切換到Message Header,點擊右上角的Add並填入以下資訊: | Action | Name | Source Type | Source Value | Data Type | | -------- | -------- | --- | --- | -------- | | Create | productIdentifier | XPath | //productIdentifier | java.lang.String | ## Step 5. Add request reply step 在上方的工具列選擇"Call"的圖示,選擇"External Call",再選擇"Request Reply",在 Content Modifier 和 End 之間點擊建立。 ![image](https://hackmd.io/_uploads/BJdGU-CtR.png) ## Step 6. Connect request reply to receiver 將Receiver拉到下方,並將Request Reply的箭頭拉到Receiver,資料格式選擇OData -> OData V2。 下方切換到Connection欄位,在Address填入`https://refapp-espm-ui-cf.cfapps.eu10.hana.ondemand.com/espm-cloud-web/espm.svc`,這是一個電商服務的 URL,可以從中獲得產品詳細資訊。 然後,切換到Processing欄位,在Resource的右方點選Select。 ![image](https://hackmd.io/_uploads/H1IvtW0YR.png) 第一步系統會自動幫你完成,點擊Step 2就好。 ![image](https://hackmd.io/_uploads/BkhqsbCtA.png) 第二步要在Select Entity選取"Products",並勾選Select All Field後,點選下方的Step 3. ![image](https://hackmd.io/_uploads/BJ_L2-RKA.png) 第三步設定Filter by,選擇ProductID,"Equals"、輸入`${header.productIdentifier}`,然後按下Finish。 ![image](https://hackmd.io/_uploads/B16hpWRFC.png) ![image](https://hackmd.io/_uploads/SJeQG0-RFR.png) **最後,記得點擊右上角的Save。** 現在,OData adapter已經配置成根據 HTTP 呼叫進行時,作為輸入發送的產品 ID 來獲取產品的詳細資訊。 ## Step 7. Deploy the integration flow 將Integration flow部屬到雲端上。點選右上角的Deploy,並選擇Yes。如果有出現這個畫面,那就是部屬成功了。 ![image](https://hackmd.io/_uploads/B1lxJGCY0.png) # Expose Integration Flow Endpoint as API and Test the Flow https://developers.sap.com/tutorials/cp-starter-isuite-api-management.html ## Step 1. Get endpoint of the integration flow 點擊旁邊的Nevigate to Manage Integration Content,然後複製endpoint。 ![image](https://hackmd.io/_uploads/rkJ_WGRtC.png) ![image](https://hackmd.io/_uploads/ByTRZGAtA.png) ## Step 2. Define the API 1. 在左側欄位選取Setting -> APIs。點擊後會跑一段時間,一旦完成後,這個帳戶的Setting就不會再出現APIs的選項了。 ![image](https://hackmd.io/_uploads/rkWv7zCKC.png) 然後選取Configure,點選API,並點擊右上角的Create建立新的API。填入以下資訊後,按下Create。 ![image](https://hackmd.io/_uploads/Hy6G2by5R.png) | Select | URL | Name | Title | API Base Path | | ------ | --- | ---- | ----- | ------------- | | URL | 將複製的Endnode貼上,並去掉`/details` | RequestProductDetails | Product Details API | /products | 2. 在上方選取切換到Resource介面,點擊Add,填入欄位資料並將POST以外的所有Operation全部清除,最後按下OK。 | Tag | Path Prefix | | -------- | -------- | | Product Details | /details | ![image](https://hackmd.io/_uploads/BkeXfGk5A.png) ![image](https://hackmd.io/_uploads/B1BcMM15R.png) 3. 點擊右上角的Deploy,當Status顯示為Deployed後,就表示API部署完成了。 ![image](https://hackmd.io/_uploads/BJscEzk9C.png) :::warning 記得切換到Edit狀態,否則會找不到Deploy的按鈕。完成後要記得按下Save,否則下一個步驟會找不到按鈕。 ::: 4. 點擊右上角的"Edit in API Manager",進入API的編輯介面,將第二個Payload改成productIdentifier,並加入一個example欄位,內容為HT-2000,最後按下Save。 ![image](https://hackmd.io/_uploads/rkcSLGy90.png) ![image](https://hackmd.io/_uploads/ryKHvzy90.png) :::warning example需要用手動輸入,才能選取名為example的keyword,否則變數有可能會不起作用。 ::: 5. 回到Configure -> APIs,進入RequestProductDetails,切換到Resource介面,將綠色的POST展開,點擊Try out並按下Execute。 ![image](https://hackmd.io/_uploads/HkESCfJ9C.png) ![image](https://hackmd.io/_uploads/HJCr0f15A.png) ![image](https://hackmd.io/_uploads/H1PIAf1c0.png) 如果出現401,那在"現階段"就沒有問題了。 :::warning 有時候可能因為瀏覽器問題,會出現405的錯誤訊息,目前當下找到的解決方案是用無痕模式重新登入BTP進行操作。 ::: ## Step 3. Copy credentials from service key 1. 回到SAP BTP Subaccount,選擇Services -> Instances and Subscriptions,在instance的區塊,點選Plan為integration flow的資料。 ![image](https://hackmd.io/_uploads/SyKjI4k9C.png) 在Service Keys應該只有一筆資料,選擇View後,複製裡面的JSON檔。在之後我們會需要用到 **"clientid"、"clientsecret"和"tokenurl"**。 ![image](https://hackmd.io/_uploads/SkrSP4kcA.png) ![image](https://hackmd.io/_uploads/HJ8M_EJ5A.png) ## Step 4. Assign policy template 1. 左側選取Discover -> APIs,搜尋"Connect to SAP Business Technology Platform Services"並點進去。 ![image](https://hackmd.io/_uploads/SybbYNkqR.png) 2. 切換到Artifact欄位,點擊圖示選擇copy。 ![image](https://hackmd.io/_uploads/Sk_eaNyqC.png) ![image](https://hackmd.io/_uploads/H1DA0NyqR.png) :::danger **※ 如果遇到無法copy的情況,如圖:** ![image](https://hackmd.io/_uploads/SJPt0Ny5A.png) 請回到Configure -> APIs,選擇"Policy Templates",將Cloud_Platform_Connectivity刪除後,再回到 Discover -> APIs -> Connect to SAP Business Technology Platform Services 重新複製。 ![image](https://hackmd.io/_uploads/S1XCpNJcC.png) ::: 3. 回到Configure > APIs,進入RequestProductDetails,選擇Policies。 ![image](https://hackmd.io/_uploads/H1In1B15R.png) 第一次使用時,要先點擊Policy Template,選擇"Apply",勾選Cloud_Platform_Connectivity後再點擊Apply。 ![image](https://hackmd.io/_uploads/H1wneHy9A.png) ![image](https://hackmd.io/_uploads/HyXPZrk90.png) 4. 選擇Preflow,點擊getcredential的圖示。(從左往右數第二個,如果畫面太擠,可以將旁邊的側邊欄收合,圖示會自動分散。) ![image](https://hackmd.io/_uploads/r1rozS150.png) 將前面複製的JSON檔裡面的"clientid"和"clientsecret"貼到對應的位置。 ![image](https://hackmd.io/_uploads/HkZSmHJ50.png) 點擊getoauthtoken的圖示(從左往右數第四個),將前面複製的"tokenurl"貼在註解下方的`<URL>`標籤裡面。 ![image](https://hackmd.io/_uploads/BkMV4BJ50.png) 完成後,點選右上角的Update,然後再點擊Save,最後點擊Click to Deploy。 ![image](https://hackmd.io/_uploads/Bk6V8BJc0.png) :::success 🎁 [特殊手段](https://community.sap.com/t5/technology-q-a/execution-of-servicecallout-getoauthtoken-failed-reason-responsecode-401-is/qaq-p/12608331): 如果最後的`Step 5. Execute API`仍然會出現 Error 500,可以嘗試**在getoauthtoken裡面的"tokenurl"尾端,加上`?grant_type=client_credentials`**,然後按下Update,再按下Save,最後有出現Click to Deploy的話也按下去。 原理不清楚,總之成功了(笑)。 ::: ## Step 5. Execute API 回到Configure -> APIs,進入RequestProductDetails,切換到Resource介面,將綠色的POST展開,點擊Try out並按下Execute。 這時候應該不會再顯示401、404、405、500等錯誤訊息,如果出現200,就代表API可以順利運作了。 ![image](https://hackmd.io/_uploads/ry1SvSkc0.png)