溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

發(fā)布時(shí)間:2021-12-30 10:35:22 來源:億速云 閱讀:143 作者:iii 欄目:服務(wù)器

這篇文章主要介紹“怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP”,在日常操作中,相信很多人在怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

登錄api.sap.com, 根據(jù)關(guān)鍵字SuccessFactors找到對(duì)應(yīng)的API目錄:

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

找到foundation/Platform級(jí)別的API,進(jìn)入之后,

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

選擇User Management:

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

點(diǎn)擊Logon,以使用API控制臺(tái)自帶的控制功能:

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

點(diǎn)擊Try Out, 就可以像使用postman一樣,使用這個(gè)API控制臺(tái)自帶的測(cè)試功能了:

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

$filter string里可以測(cè)試這個(gè)OData API的filter操作:

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

從測(cè)試結(jié)果可以發(fā)現(xiàn),firstName為Sami的user,在這個(gè)sandbox系統(tǒng)里的user ID為50004:

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

點(diǎn)擊Show API Key,拿到一個(gè)API key,這樣就能在該API控制臺(tái)以外的地方調(diào)用API.

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

點(diǎn)擊Code Snipet,可以把自動(dòng)生成的API調(diào)用代碼復(fù)制下來,直接粘貼到應(yīng)用里使用。

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

點(diǎn)擊Curl,獲得使用工具curl進(jìn)行測(cè)試的命令行:

怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP

> 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的ABAP編程環(huán)境里消費(fèi)API的ABAP

在SAP UI5應(yīng)用里消費(fèi)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編程環(huán)境里消費(fèi)API的ABAP

在SAP云平臺(tái)ABAP編程環(huán)境里消費(fèi)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 }| ).

到此,關(guān)于“怎么在SAP的ABAP編程環(huán)境里消費(fèi)API的ABAP”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI