登錄api.sap.com, 根據(jù)關(guān)鍵字SuccessFactors找到對應(yīng)的API目錄:
找到foundation/Platform級別的API,進入之后,
選擇User Management:
點擊Logon,以使用API控制臺自帶的控制功能:
點擊Try Out, 就可以像使用postman一樣,使用這個API控制臺自帶的測試功能了:
$filter string里可以測試這個OData API的filter操作:
從測試結(jié)果可以發(fā)現(xiàn),firstName為Sami的user,在這個sandbox系統(tǒng)里的user ID為50004:
點擊Show API Key,拿到一個API key,這樣就能在該API控制臺以外的地方調(diào)用API.
點擊Code Snipet,可以把自動生成的API調(diào)用代碼復制下來,直接粘貼到應(yīng)用里使用。
點擊Curl,獲得使用工具curl進行測試的命令行:
curl --request GET --url "https://sandbox.api.sap.com/successfactors/odata/v2/User" --header "APIKey: e9ZLBOfexchhHN" --header "Accept: application/json" --header "Content-Type: application/json"
curl --request GET --url "https://sandbox.api.sap.com/successfactors/odata/v2/User" --header "APIKey: e9ZLBOkMUexchhHN" --header "Accept: application/json" --header "Content-Type: application/json"
API endpoint for API sandbox
Optional query parameters: "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/odata/v2
https://api4.successfactors.com/odata/v2
https://apisalesdemo4.successfactors.com/odata/v2
https://api4preview.sapsf.com/odata/v2
https://api5.successfactors.eu/odata/v2
https://api8.successfactors.com/odata/v2
https://apisalesdemo8.successfactors.com/odata/v2
https://api8preview.sapsf.com/odata/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/odata/v2
https://api15.sapsf.cn/odata/v2
https://api16.sapsf.eu/odata/v2
https://api17preview.sapsf.com/odata/v2
https://api17.sapsf.com/odata/v2
https://api18preview.sapsf.com/odata/v2
https://api18.sapsf.com/odata/v2
得到的結(jié)果:
也可以通過select操作,讓API只返回firstName和lastName兩個字段的值:
curl --request GET --url "https://sandbox.api.sap.com/successfactors/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/successfactors/odata/v2/User,UserPermissions/User?%24top-5&%24select=firstName%2ClastName" --header "APIKey: e9ZibykWXsAfkMUexchhHN" --header "Accept: application/json" --header "Content-Type: application/json"
在SAP UI5應(yīng)用里消費API的代碼:
//Create JSON Model with URLvar oModel = new sap.ui.model.json.JSONModel();//API Key for API Sandboxvar 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("https://sandbox.api.sap.com/successfactors/odata/v2/User", null, true, "GET", null, false, sHeaders);//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/odata/v2//https://api4.successfactors.com/odata/v2//https://apisalesdemo4.successfactors.com/odata/v2//https://api4preview.sapsf.com/odata/v2//https://api5.successfactors.eu/odata/v2//https://api8.successfactors.com/odata/v2//https://apisalesdemo8.successfactors.com/odata/v2//https://api8preview.sapsf.com/odata/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/odata/v2//https://api15.sapsf.cn/odata/v2//https://api16.sapsf.eu/odata/v2//https://api17preview.sapsf.com/odata/v2//https://api17.sapsf.com/odata/v2//https://api18preview.sapsf.com/odata/v2//https://api18.sapsf.com/odata/v2//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.//https://sapui5.hana.ondemand.com/#docs/guide/96804e3315ff440aa0a50fd290805116.html#loio96804e3315ff440aa0a50fd290805116//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編程環(huán)境里消費API的ABAP代碼:
TRY."create http destination by url; API endpoint for API sandbox DATA(lo_http_destination) = cl_http_destination_provider=>create_by_url( 'https://sandbox.api.sap.com/successfactors/odata/v2/User' ). "alternatively create HTTP destination via destination service "cl_http_destination_provider=>create_by_cloud_destination( i_name = '<...>' " i_service_instance_name = '<...>' ) "SAP Help: https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/f871712b816943b0ab5e04b60799e518.html"Available API Endpoints"https://api2.successfactors.eu/odata/v2"https://apisalesdemo2.successfactors.eu/odata/v2"https://api2preview.sapsf.eu/odata/v2"https://api4.successfactors.com/odata/v2"https://apisalesdemo4.successfactors.com/odata/v2"https://api4preview.sapsf.com/odata/v2"https://api5.successfactors.eu/odata/v2"https://api8.successfactors.com/odata/v2"https://apisalesdemo8.successfactors.com/odata/v2"https://api8preview.sapsf.com/odata/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/odata/v2"https://api15.sapsf.cn/odata/v2"https://api16.sapsf.eu/odata/v2"https://api17preview.sapsf.com/odata/v2"https://api17.sapsf.com/odata/v2"https://api18preview.sapsf.com/odata/v2"https://api18.sapsf.com/odata/v2"create HTTP client by destinationDATA(lo_web_http_client) = cl_web_http_client_manager=>create_by_http_destination( lo_http_destination ) ."adding headers with API Key for API SandboxDATA(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 requestDATA(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 handlingENDTRY."uncomment the following line for console output; prerequisite: code snippet is implementation of if_oo_adt_classrun~main"out->write( |response: { lv_response }| ).
要獲取更多Jerry的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":