怎么在SAP的ABAP编程环境里消费API的ABAP-创新互联
这篇文章主要介绍“怎么在SAP的ABAP编程环境里消费API的ABAP”,在日常操作中,相信很多人在怎么在SAP的ABAP编程环境里消费API的ABAP问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么在SAP的ABAP编程环境里消费API的ABAP”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
来安网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联建站成立于2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站。登录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://cessfactors/odata/v2/Userhttps://cessfactors/odata/v2/Userhttps://odata/v2https:///odata/v2https://ata/v2https:///odata/v2https:///odata/v2https://data/v2https://odata/v2https:///odata/v2https:///odata/v2https://data/v2https:///odata/v2https://odata/v2https:///odata/v2https:///odata/v2https://data/v2https://
#https://
#https://odata/v2https://2https://odata/v2https://2https://cessfactors/odata/v2/https://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("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编程环境里消费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( '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: SAP Help Portal "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 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 }| ).
到此,关于“怎么在SAP的ABAP编程环境里消费API的ABAP”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联-成都网站建设公司网站,小编会继续努力为大家带来更多实用的文章!
文章标题:怎么在SAP的ABAP编程环境里消费API的ABAP-创新互联
文章地址:http://azwzsj.com/article/desich.html