使用SAP API portal進行SAP SuccessFactors的API測試
登入api.sap.com, 根據關鍵字SuccessFactors找到對應的API目錄:
找到foundation/Platform級別的API,進入之後,
選擇User Management:
點選Logon,以使用API控制檯自帶的控制功能:
點選Try Out, 就可以像使用postman一樣,使用這個API控制檯自帶的測試功能了:
$filter string裡可以測試這個OData API的filter操作:
從測試結果可以發現,firstName為Sami的user,在這個sandbox系統裡的user ID為50004:
點選Show API Key,拿到一個API key,這樣就能在該API控制檯以外的地方呼叫API.
點選Code Snipet,可以把自動生成的API呼叫程式碼複製下來,直接貼上到應用裡使用。
點選Curl,獲得使用工具curl進行測試的命令列:
> curl --request GET --url " https:// sandbox.api.sap.com/suc cessfactors/odata/v2/User " --header "APIKey: e9ZLBOfexchhHN" --header "Accept: application/json" --header "Content-Type: application/json"
> curl --request GET --url " https:// sandbox.api.sap.com/suc cessfactors/odata/v2/User " --header "APIKey: e9ZLBOkMUexchhHN" --header "Accept: application/json" --header "Content-Type: application/json"
#API endpoint for API sandbox
#Optional query parameters: "$top" , "$skip"
#To view the complete list of query parameters, see its API definition.
#Available API Endpoints
# https:// api2.successfactors.eu/ odata/v2
# https:// apisalesdemo2.successfactors.eu /odata/v2
# https:// api2preview.sapsf.eu/od ata/v2
# https:// api4.successfactors.com /odata/v2
# https:// apisalesdemo4.successfactors.com /odata/v2
# https:// api4preview.sapsf.com/o data/v2
# https:// api5.successfactors.eu/ odata/v2
# https:// api8.successfactors.com /odata/v2
# https:// apisalesdemo8.successfactors.com /odata/v2
# https:// api8preview.sapsf.com/o data/v2
# https:// api10.successfactors.com /odata/v2
# https:// api10preview.sapsf.com/ odata/v2
# https:// api012.successfactors.eu /odata/v2
# https:// apirot.successfactors.eu /odata/v2
# https:// api12preview.sapsf.eu/o data/v2
# https:// api15.sapsf.cn/odata/v2
# https:// api16.sapsf.eu/odata/v2
# https:// api17preview.sapsf.com/ odata/v2
# https:// api17.sapsf.com/odata/v 2
# https:// api18preview.sapsf.com/ odata/v2
# https:// api18.sapsf.com/odata/v 2
得到的結果:
也可以透過select操作,讓API只返回firstName和lastName兩個欄位的值:
curl --request GET --url " https:// sandbox.api.sap.com/suc cessfactors/odata/v2/
User,UserPermissions/User?%24top-5&%24select=firstName%2ClastName" --header 'APIKey: e9ZLBOXsAfkMUexchhHN' --header 'Accept: application/ison' --header "Content-Type: application/ison"
curl --request GET --url " https:// sandbox.api.sap.com/suc cessfactors/odata/v2/User,UserPermissions/User?%24top-5&%24select=firstName%2ClastName " --header "APIKey: e9ZibykWXsAfkMUexchhHN" --header "Accept: application/json" --header "Content-Type: application/json"
在SAP UI5應用裡消費API的程式碼:
```JavaScript
//Create JSON Model with URL
var oModel = new sap.ui.model.json.JSONModel();
//API Key for API Sandbox
var sHeaders = {"Content-Type":"application/json","Accept":"application/json","APIKey":"e9ZLBOfIplCOnibykWXsAfkMUexchhHN"};
//Available Security Schemes for productive API Endpoints
//Basic Authentication
//Basic Auth : provide username:password in Base64 encoded in Authorization header
//sending request
//API endpoint for API sandbox
oModel.loadData(");
//Optional query parameters: "$top" , "$skip"
//To view the complete list of query parameters, see its API definition.
//Available API Endpoints
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//You can assign the created data model to a View and UI5 controls can be bound to it. Please refer documentation available at the below link for more information.
//
//The below code snippet for printing on the console is for testing/demonstration purpose only. This must not be done in real UI5 applications.
oModel.attachRequestCompleted(function(oEvent){
var oData = oEvent.getSource().oData;
console.log(oData);
});
```
在SAP雲平臺ABAP程式設計環境裡消費API的ABAP程式碼:
```ABAP
TRY.
"create http destination by url; API endpoint for API sandbox
DATA(lo_http_destination) =
cl_http_destination_provider=>create_by_url( ').
"alternatively create HTTP destination via destination service
"cl_http_destination_provider=>create_by_cloud_destination( i_name = '<...>'
" i_service_instance_name = '<...>' )
"SAP Help: SAP Help Portal
"Available API Endpoints
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"create HTTP client by destination
DATA(lo_web_http_client) = cl_web_http_client_manager=>create_by_http_destination( lo_http_destination ) .
"adding headers with API Key for API Sandbox
DATA(lo_web_http_request) = lo_web_http_client->get_http_request( ).
lo_web_http_request->set_header_fields( VALUE #(
( name = 'Content-Type' value = 'application/json' )
( name = 'Accept' value = 'application/json' )
( name = 'APIKey' value = 'e9ZLBOfIplCOnibykWXsAfkMUexchhHN' )
) ).
"Available Security Schemes for productive API Endpoints
"Bearer and Basic Authentication
"lo_web_http_request->set_authorization_bearer( i_bearer = '<...>' ).
"lo_web_http_request->set_authorization_basic( i_username = '<...>' i_password = '<...>' ).
"set request method and execute request
DATA(lo_web_http_response) = lo_web_http_client->execute( if_web_http_client=>GET ).
DATA(lv_response) = lo_web_http_response->get_text( ).
CATCH cx_http_dest_provider_error cx_web_http_client_error cx_web_message_error.
"error handling
ENDTRY.
"uncomment the following line for console output; prerequisite: code snippet is implementation of if_oo_adt_classrun~main
"out->write( |response: { lv_response }| ).
```
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2677577/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP API management portal - 如何建立API providerAPIIDE
- 如何使用 SAP API Portal Policy Editor 給 SAP API 呼叫自動新增認證資訊API
- 使用jMeter對基於SAP ID service進行Authentication的Restful API進行併發測試JMeterRESTAPI
- 在SAP雲平臺的API portal裡建立和管理APIAPI
- 使用 HTTPie 進行 API 測試HTTPAPI
- 使用PostMan進行API測試PostmanAPI
- 使用SAP WebIDE消費API Portal裡建立的API時的錯誤訊息WebIDEAPI
- 如何為SAP API Portal上建立的API增添API key驗證保護功能API
- SAP Spartacus 裡 對 isPlatformBrowser API 的使用PlatformAPI
- 使用 SAP UI5 sap.ui.export.Spreadsheet API 進行 Excel 匯出的一些限制UIExportAPIExcel
- 使用SAP CRM mock框架進行單元測試的設計Mock框架
- Angular HTTPClient API 在 SAP 電商雲中的使用AngularHTTPclientAPI
- API 測試 | 瞭解 API 介面測試 | API 介面測試指南API
- 使用類似搭積木的低程式碼開發方式進行SAP API開發API
- 問下 API 閘道器進行測試的方法API
- API測試:瞭解API介面測試與API介面測試指南API
- 使用Spring Boot REST API進行測試驅動開發Spring BootRESTAPI
- Golang 專案中如何對 API 進行測試?GolangAPI
- SAP Marketing Cloud Restful API SDK 使用案例分享CloudRESTAPI
- SAP 電商雲 Spartacus UI 同 SAP Customer Data Cloud 整合執行時的 apiUICloudAPI
- 使用 jMeter 對需要 User Authentication 的 Restful API 進行併發負載測試JMeterRESTAPI負載
- 如何基於eoLinker進行API介面測試工作API
- 使用Java程式消費SAP Leonardo的機器學習APIJava機器學習API
- 關於 SAP UI5 Device API 的使用介紹UIdevAPI
- SAP API開發方法大全API
- SAP UI5 sap.ui.export.Spreadsheet API 介紹UIExportAPI
- SAP官方提供的人臉識別APIAPI
- SAP Data Intelligence API執行出錯的排錯之道IntelAPI
- 使用Pandaria編寫API自動化測試進階用法API
- Postman之API測試使用全指南PostmanAPI
- API測試之Postman使用全指南APIPostman
- 使用 YApi 管理 API 文件,測試, mockAPIMock
- SAP UI5 裝置型別檢測 Device API 的工作原理UI型別devAPI
- 使用SAP WebIDE進行SAP Cloud Platform Business Application開發WebIDECloudPlatformAPP
- 運用 Hacking APIs GPT 進行 API 安全性測試APIGPT
- API自動化測試平臺,支援場景化的API測試API
- SAP ABAP MIME Repository 和 API 介紹API
- Document flow API in SAP CRM and C4CAPI