Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

404 error on accessing REST API ABAP

vikash_pathak
Participant
0 Kudos

Hello ,

I am using REST API to Read data from sharepoint which is in excel file ,

on first access i am able to get data with 200 response , but when i am accessing it for second time its getting response code 404 .

please share the solution.

below is the code which i have used to read data

*&---------------------------------------------------------------------*<br>*& Report <br>*&---------------------------------------------------------------------*<br>*&<br>*&---------------------------------------------------------------------*<br>REPORT zcloseair_int.<br><br>DATA : "LT_RESULT TYPE STANDARD TABLE OF TY_RESULT,<br>  lv_code   TYPE i,<br>  lv_reason TYPE string,<br>  cn_stored TYPE recabool.<br><br>DATA: lv_url   TYPE string.<br>DATA: lv_url_token   TYPE string.<br>DATA: lv_result TYPE string.<br>DATA: lv_result1 TYPE xstring.<br>DATA: response   TYPE string,<br>      response_x TYPE xstring,<br>      lv_url1    TYPE string,<br>      lv_auth    TYPE string,<br>      lv_auth2   TYPE string.<br><br><br>CONSTANTS : lv_initial_url TYPE string VALUE '<Your API>',<br>            lc_delimiter   TYPE cl_rsda_csv_converter=>char VALUE  '"',<br>            lc_separator   TYPE cl_rsda_csv_converter=>char VALUE  ','.<br><br><br>*** Getting Token<br><br>TYPES:<br>  BEGIN OF t_entry,<br>    access_token TYPE string,<br>    token_type   TYPE string,<br>    expires_in   TYPE n LENGTH 8,<br>    scope        TYPE string,<br>    jti          TYPE string,<br>  END OF t_entry .<br><br>TYPES:<br>  t_entry_map TYPE SORTED TABLE OF t_entry WITH UNIQUE KEY access_token.<br>DATA: m_entries TYPE t_entry.<br>DATA: lr_instance  TYPE REF TO  /ui5/cl_json_parser.<br><br>DATA: lo_http_client TYPE REF TO if_http_client. "HTTP Client Abstraction<br>DATA: lv_length TYPE i,<br>      lt_binary TYPE STANDARD TABLE OF x255.<br>DATA: it_line TYPE TABLE OF string.<br>DATA: it_line1 TYPE TABLE OF string.<br>SPLIT lv_result AT cl_abap_char_utilities=>cr_lf INTO TABLE it_line.<br>TYPES: BEGIN OF ty_data,<br>         xblnrs      TYPE string,<br>         bukrs       TYPE bukrs,<br>         blart       TYPE blart,<br>         bldat       TYPE bldat,<br>         budat       TYPE budat,<br>         xblnr       TYPE xblnr,<br>         buzei       TYPE buzei,<br>         waers       TYPE waers,<br>         bktxt       TYPE bktxt,<br>         xref1       TYPE xref1,<br>         xref2       TYPE xref2,<br>         newbs       TYPE newbs,<br>         newko       TYPE newko,<br>         customer    TYPE string,<br>         account     TYPE num6,<br>         newum       TYPE newum,<br>         wrbtr       TYPE char26,<br>         dmbtr       TYPE char26,<br>         hkont       TYPE hkont,<br>         zfbdt       TYPE char10, "zfbdt,<br>         zterm       TYPE char4, "zterm,<br>         zlsch       TYPE char1, "zlsch,<br>         zuonr       TYPE char18, "zuonr,<br>         sgtxt       TYPE sgtxt,<br>         Name        TYPE string,<br>         ort01       TYPE ort01,<br>         pstlz       TYPE pstlz,<br>         land1       TYPE land1,<br>         aufnr       TYPE aufnr,<br>         prctr       TYPE prctr,<br>         kostl       TYPE kostl,<br>         xref1s       TYPE xref1,<br>         xref2s       TYPE xref2,<br>         xref3       TYPE xref3,<br>         kidno       TYPE kidno,<br>*         hkont     TYPE hkont,<br>         secco       TYPE secco,<br>         gsber       TYPE gsber,<br>         qsskz       TYPE qsskz,<br>         qsshb       TYPE char26, "qsshb,<br>         bupla       TYPE bupla,<br>         xmwst       TYPE xmwst,<br>         mwskz       TYPE mwskz,<br>         valut       TYPE valut,<br>         projk       TYPE char24,<br>         sap_poj_cod TYPE char24,<br>       END OF ty_data.<br>DATA: lt_data  TYPE STANDARD TABLE OF ty_data,<br>      lt_data1 TYPE TABLE OF ty_data,<br>      ls_data  TYPE ty_data.<br>DATA: wa_documentheader    TYPE bapiache09,<br>      wa_obj               TYPE bapiache09,<br>      it_accountgl         TYPE TABLE OF bapiacgl09,<br>      it_accountreceivable TYPE TABLE OF bapiacar09,<br>      it_currencyamount    TYPE TABLE OF bapiaccr09,<br>      it_return            TYPE TABLE OF bapiret2,<br>      wa_accountgl         TYPE bapiacgl09,<br>      wa_accountreceivable TYPE bapiacar09,<br>      wa_currencyamount    TYPE bapiaccr09,<br>      wa_return            TYPE bapiret2.<br>***///  Accessing API To get The Token<br>lv_url_token = 'https://zzzzz.accesscontrol.windows.net/e83d39e6-f19d-49ca-8261-07ae0659a01c/tokens/OAuth/2/'.<br>CLEAR lo_http_client.<br>CALL METHOD cl_http_client=>create_by_url<br>  EXPORTING<br>    url                        = lv_url_token<br>  IMPORTING<br>    client                     = lo_http_client<br>  EXCEPTIONS<br>    argument_not_found         = 1<br>    plugin_not_active          = 2<br>    internal_error             = 3<br>    pse_not_found              = 4<br>    pse_not_distrib            = 5<br>    pse_errors                 = 6<br>    oa2c_set_token_error       = 7<br>    oa2c_missing_authorization = 8<br>    oa2c_invalid_config        = 9<br>    oa2c_invalid_parameters    = 10<br>    oa2c_invalid_scope         = 11<br>    oa2c_invalid_grant         = 12<br>    OTHERS                     = 13.<br>IF sy-subrc <> 0.<br>ELSE.<br>  lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.<br><br><br><br>  CALL METHOD lo_http_client->request->set_method<br>    EXPORTING<br>      method = 'POST'.<br><br>**Fill header data<br>  CALL METHOD lo_http_client->request->set_header_field<br>    EXPORTING<br>      name  = 'Content-Type'<br>      value = 'application/x-www-form-urlencoded'.<br>  CALL METHOD lo_http_client->request->set_form_field<br>    EXPORTING<br>      name  = 'grant_type'<br>      value = 'refresh_token'.<br><br>  CALL METHOD lo_http_client->request->set_form_field<br>    EXPORTING<br>      name  = 'client_id'<br>      value = 'zzzzzz'.<br><br>  CALL METHOD lo_http_client->request->set_form_field<br>    EXPORTING<br>      name  = 'client_secret'<br>      value = 'zzzzzz'.<br><br>  CALL METHOD lo_http_client->request->set_form_field<br>    EXPORTING<br>      name  = 'resource'<br>      value = 'zzzzzzzzz'.<br>  CALL METHOD lo_http_client->request->set_form_field<br>    EXPORTING<br>      name  = 'refresh_token'<br>      value = 'zzzzzz' &&<br>              'zzzzzzzzzzz'.<br>  lo_http_client->send( ).<br><br><br>  lo_http_client->receive(<br>    EXCEPTIONS<br>      http_communication_failure = 1<br>      http_invalid_state         = 2<br>      http_processing_failed     = 3 ).<br><br>  CALL METHOD lo_http_client->response->get_status<br>    IMPORTING<br>      code   = lv_code<br>      reason = lv_reason.<br><br>*** Read the result<br>  CLEAR lv_result .<br><br>  lv_result = lo_http_client->response->get_cdata( ).<br><br><br><br><br>  CREATE OBJECT lr_instance.<br><br>  IF lv_result IS NOT INITIAL. "Retrieving your Token here<br>    response = lv_result.<br><br>    /ui2/cl_json=>deserialize(<br>      EXPORTING<br>        json        = response<br>        pretty_name = /ui2/cl_json=>pretty_mode-camel_case<br>      CHANGING<br>        data        = m_entries ).<br><br>    lv_auth2 = m_entries-access_token.                      "+0(1016).<br>    SHIFT lv_auth2 RIGHT DELETING TRAILING space.<br>    CONDENSE lv_auth2.<br>    response = response+17.<br><br>    CONCATENATE 'Bearer' lv_auth2 INTO lv_auth SEPARATED BY space. "Using Token Value create your Authorization Code<br>  ENDIF.<br><br><br>  CALL METHOD lo_http_client->response->get_raw_message<br>    RECEIVING<br>      data = lv_result1.<br><br>  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'<br>    EXPORTING<br>      buffer        = lv_result1<br>*     APPEND_TO_TABLE       = ' '<br>    IMPORTING<br>      output_length = lv_length<br>    TABLES<br>      binary_tab    = lt_binary.<br><br>  CALL FUNCTION 'SCMS_BINARY_TO_STRING'<br>    EXPORTING<br>      input_length = lv_length<br>    IMPORTING<br>      text_buffer  = lv_result<br>    TABLES<br>      binary_tab   = lt_binary<br>    EXCEPTIONS<br>      failed       = 1<br>      OTHERS       = 2.<br>ENDIF.<br>lv_url = 'https://zzzzzz.sharepoint.com/sites/galaxy/_api/Web/GetFileByServerRelativeUrl(''/sites/galaxy/Accounts/wwwww_closeAir_Interface/Expenses/Invoice_test1.csv'')/$value'.<br><br>CLEAR lo_http_client.<br>CALL METHOD cl_http_client=>create_by_url<br>  EXPORTING<br>    url                        = lv_url<br>  IMPORTING<br>    client                     = lo_http_client<br>  EXCEPTIONS<br>    argument_not_found         = 1<br>    plugin_not_active          = 2<br>    internal_error             = 3<br>    pse_not_found              = 4<br>    pse_not_distrib            = 5<br>    pse_errors                 = 6<br>    oa2c_set_token_error       = 7<br>    oa2c_missing_authorization = 8<br>    oa2c_invalid_config        = 9<br>    oa2c_invalid_parameters    = 10<br>    oa2c_invalid_scope         = 11<br>    oa2c_invalid_grant         = 12<br>    OTHERS                     = 13.<br>IF sy-subrc <> 0.<br>ENDIF.<br><br>lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.<br><br>CALL METHOD lo_http_client->request->set_method<br>  EXPORTING<br>    method = 'GET'.<br><br>*Fill header data<br>* CALL METHOD lo_http_client->request->set_header_field<br>*    EXPORTING<br>*      name  = 'Content-Type'<br>*      value = 'application/x-www-form-urlencoded'.<br><br>CALL METHOD lo_http_client->request->set_header_field<br>  EXPORTING<br>    name  = 'Content-Type'<br>    value = 'application/json; odata=verbose'.<br><br>CALL METHOD lo_http_client->request->set_header_field<br>  EXPORTING<br>    name  = 'Accept'<br>    value = 'application/json; odata=verbose'.<br><br>CALL METHOD lo_http_client->request->set_header_field<br>  EXPORTING<br>    name  = 'Authorization'<br>    value = lv_auth.<br><br>lo_http_client->send( ).<br><br><br>lo_http_client->receive(<br>  EXCEPTIONS<br>    http_communication_failure = 1<br>    http_invalid_state         = 2<br>    http_processing_failed     = 3 ).<br><br>CALL METHOD lo_http_client->response->get_status<br>  IMPORTING<br>    code   = lv_code<br>    reason = lv_reason.<br><br>*** Read the result<br>CLEAR lv_result .<br>lv_result = lo_http_client->response->get_cdata( ).<br><br>*DATA:lt_data_t TYPE STANDARD TABLE OF string.<br>SPLIT lv_result AT cl_abap_char_utilities=>cr_lf INTO TABLE DATA(lt_data_t).<br>*SPLIT lv_result AT |\r\n| INTO TABLE DATA(lines).<br><br>DATA(lo_csv_converter) = cl_rsda_csv_converter=>create(<br>                               i_delimiter = lc_delimiter<br>                               i_separator = lc_separator ).<br>*DATA(lr_rsda) = NEW cl_rsda_csv_converter( ).<br>DATA(ls_structure)   = VALUE ty_data( ).<br>LOOP AT lt_data_t<br>  ASSIGNING FIELD-SYMBOL(<lfs_data>).<br><br>  lo_csv_converter->csv_to_structure(<br>    EXPORTING<br>      i_data   = <lfs_data>                 " I_DATA<br>    IMPORTING<br>      e_s_data = ls_structure                 " E_S_DATA<br>  ).<br>  IF sy-tabix EQ 1.<br>    CONTINUE.<br>  ELSE.<br>    APPEND ls_structure TO lt_data.<br>  ENDIF.<br><br>ENDLOOP.<br><br>lo_http_client->close( ).<br><br><br><br>**///// Selecting Data From Maping Tables.<br>SELECT * FROM zproject_map<br>         INTO TABLE @DATA(li_PROJECT_MAP).<br><br>SELECT * FROM zglcode_map<br>          INTO TABLE @DATA(li_ZGLCODE_MAP).<br><br>SELECT * FROM zcustomer_map<br>         INTO TABLE @DATA(li_zcustomer_map).<br><br>**///// Selecting Data From Maping Tables.<br><br><br>LOOP AT lt_data INTO ls_data.<br>*  IF sy-tabix <> 1.<br>* clear the variables<br>  CLEAR: it_accountgl, it_accountreceivable, it_currencyamount, it_return.<br>  CLEAR: wa_documentheader, wa_obj.<br>**********************************************************************<br>* Header<br>**********************************************************************<br>* Document Date<br>  wa_documentheader-doc_date     = ls_data-bldat.<br>* Posting Date<br>  wa_documentheader-pstng_date   =  ls_data-budat.<br>* Document Type<br>  wa_documentheader-doc_type     =  'RV'. "ls_data-blart.<br>* Company Code<br>  wa_documentheader-comp_code    =  ls_data-bukrs.<br>* Document Header Text<br>  wa_documentheader-header_txt   =  ls_data-bktxt.<br>* Creator User name<br>  wa_documentheader-username     =  sy-uname.<br>**********************************************************************<br>* Item<br>**********************************************************************<br>  CLEAR wa_accountreceivable.<br>*       Item number<br>  ls_data-buzei = ls_data-buzei + 1.<br>  wa_accountreceivable-itemno_acc = ls_data-buzei.<br>*       General Ledger Account<br>  DATA(ls_ZGLCODE_MAP) = VALUE #( li_ZGLCODE_MAP[ openar_glcode = ls_data-hkont ] OPTIONAL ).<br>  wa_accountreceivable-gl_account = COND #( WHEN ls_ZGLCODE_MAP IS NOT INITIAL<br>                                              THEN ls_ZGLCODE_MAP-sap_gl_code<br>                                              ELSE ls_data-hkont ).<br>*       Item Text<br>  wa_accountreceivable-item_text = ls_data-sgtxt.<br>*       Customer Number<br>  DATA(ls_zcustomer_map) = VALUE #( li_zcustomer_map[ ex_kunnr = ls_data-customer ] OPTIONAL ).<br>  wa_accountreceivable-customer = COND #( WHEN ls_zcustomer_map IS NOT INITIAL<br>                                          THEN ls_zcustomer_map-in_kunnr<br>                                          ELSE ls_data-customer ).<br>*       Terms of Payment Key<br>  wa_accountreceivable-pmnttrms = ls_data-zterm.<br>*       Baseline Date for Due Date Calculation<br>  wa_accountreceivable-bline_date = ls_data-zfbdt.<br>  APPEND wa_accountreceivable TO it_accountreceivable.<br>  CLEAR wa_currencyamount.<br><br>  wa_currencyamount-itemno_acc = ls_data-buzei.<br>*       Currency<br>  wa_currencyamount-currency = ls_data-waers.<br>*       Amount in Document Currency<br>  wa_currencyamount-amt_doccur = ls_data-wrbtr.<br><br>  APPEND wa_currencyamount TO it_currencyamount.<br>  ls_data-buzei = ls_data-buzei + 1.<br>  wa_currencyamount-amt_doccur = wa_currencyamount-amt_doccur * -1.<br>  APPEND wa_currencyamount TO it_currencyamount.<br><br>*  DATA(ls_ZPROJECT_MAP) = VALUE #( li_ZPROJECT_MAP[ ex_projk = ls_data-zuonr ] OPTIONAL ).<br><br><br>  INSERT VALUE #( itemno_acc     = 1<br>                  gl_account     = COND #( WHEN ls_ZGLCODE_MAP IS NOT INITIAL<br>                                              THEN ls_ZGLCODE_MAP-sap_gl_code<br>                                              ELSE ls_data-hkont )<br>*                  tax_code       = 'V0'<br>                  item_text      = 'BAPI Test G/L line item'<br>                  customer       = COND #( WHEN ls_zcustomer_map IS NOT INITIAL<br>                                          THEN ls_zcustomer_map-in_kunnr<br>                                          ELSE ls_data-customer )<br>*                  profit_ctr     = '0000002002'<br>*                  de_cre_ind     = 'H'<br>*                  comp_code      = 'RS01'<br>*                  doc_type       = 'DR'<br>*it_accountgl-fis_period     = '06'.<br>*it_accountgl-fisc_year      = '2009'.<br>                  pstng_date     = sy-datum ) INTO TABLE it_accountgl.<br><br><br>*   " Posting Key & Indicator: Negative posting<br>*   clear wa_extension2.<br>*   clear wa_zaccdocuext.<br>*   wa_zaccdocuext-posnr = ls_data-buzei.<br>*   wa_zaccdocuext-bschl = ls_data-bschl.<br>*   wa_extension2-structure  = 'ZACCDOCUEXT'.<br>*   wa_extension2-valuepart1 = wa_zaccdocuext.<br>*   append wa_extension2 to it_extension2.<br><br>*clear l_katyp.<br>*select single katyp<br>*   into l_katyp<br>*   from cskb<br>*   where kstar = ls_data-hkont.<br>*if l_katyp = '11'.<br>*   " Profit Segment<br>*   clear wa_criteria.<br>*   wa_criteria-itemno_acc = ls_data-buzei.<br>*   wa_criteria-fieldname = 'KAUFN'.  " Sales Order<br>*   wa_criteria-character = ls_data-vbeln.<br>*   append wa_criteria to it_criteria.<br>*   wa_criteria-fieldname = 'KDPOS'.  " Sales Order Item<br>*   wa_criteria-character = ls_data-posnr.<br>*   append wa_criteria to it_criteria.<br>*   wa_criteria-fieldname = 'KNDNR'.  " Customer<br>*   wa_criteria-character = wa_vbak-kunnr.<br>*   append wa_criteria to it_criteria.<br>*   wa_criteria-fieldname = 'ARTNR'.  " Material<br>*   wa_criteria-character = ls_data-matnr.<br>*   append wa_criteria to it_criteria.<br>*endif.<br>* Call BAPI to post document<br><br><br>  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'<br>    EXPORTING<br>      documentheader    = wa_documentheader<br>*     CUSTOMERCPD       =<br>*     CONTRACTHEADER    =<br>    IMPORTING<br>      obj_type          = wa_obj-obj_type<br>      obj_key           = wa_obj-obj_key<br>      obj_sys           = wa_obj-obj_sys<br>    TABLES<br>      accountgl         = it_accountgl<br>      accountreceivable = it_accountreceivable<br>*     ACCOUNTPAYABLE    =<br>*     ACCOUNTTAX        =<br>      currencyamount    = it_currencyamount<br>*     criteria          = it_criteria<br>*     valuefield        = it_valuefield<br>*     EXTENSION1        =<br>      return            = it_return<br>*     PAYMENTCARD       =<br>*     CONTRACTITEM      =<br>*     extension2        = it_extension2<br>*     REALESTATE        =<br>*     ACCOUNTWT         =<br>    .<br>  READ TABLE it_return INTO wa_return WITH KEY type = 'E'.<br>  IF sy-subrc = 0.<br>    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.<br>*    PERFORM frm_message_display.<br>  ELSE.<br>    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'<br>      EXPORTING<br>        wait = 'X'.<br><br>  ENDIF.<br>*  ENDIF.<br>ENDLOOP.<br><br>LOOP AT it_return INTO DATA(ls_return).<br>  WRITE:/ ls_return-type,ls_return-id,<br>          ls_return-message,ls_return-message_v1,<br>          ls_return-parameter.<br><br>ENDLOOP.<br>

Thanks

Vikash

5 REPLIES 5

Sandra_Rossi
Active Contributor
0 Kudos

Isn't it OAuth2?

Your first HTTP request is to get the token.

Your second HTTP request is to run the API and it's 404 which means not found.

You say the second one returns 404 page not found, it means that the URL is invalid

https://zzzzzz.sharepoint.com/sites/galaxy/_api/Web/GetFileByServerRelativeUrl

0 Kudos

Hi, 404 error means connection refused, if URL is wrong it will not be accessible even on first time, but as i mentioned i am able to access for the first time i am getting data from both of the the API's , but when i execute for second time the second url https://zzzzzz.sharepoint.com/sites/galaxy/_api/Web/GetFileByServerRelativeUrl returns 404 error 'Connection refused'

0 Kudos

Weird to have 404 page not found with a different error reason.

Usually it's 401 or 403 for login error or whatever.

HTTP 404 - Wikipedia

Anyway, did you try to do 3 requests, 1 to get a token followed by 2 calls to API?

  1. get a token
  2. call GetFileByServerRelativeUrl with token above
  3. call again GetFileByServerRelativeUrl with same token

Does it work? (it should, because the token has a sufficient expiration time)

Hi sandra,

no it didn't work , still returning 404 connection refused

lv_url_token = 'https://zzzzz.accesscontrol.windows.net/e83d39e6-f19d-49ca-8261-07ae0659a01c/tokens/OAuth/2/'.
CLEAR lo_http_client.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url_token
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
pse_not_found = 4
pse_not_distrib = 5
pse_errors = 6
oa2c_set_token_error = 7
oa2c_missing_authorization = 8
oa2c_invalid_config = 9
oa2c_invalid_parameters = 10
oa2c_invalid_scope = 11
oa2c_invalid_grant = 12
OTHERS = 13.
IF sy-subrc <> 0.
ELSE.
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.

* lo_http_client->authenticate(
* EXPORTING
* username = 'sonal.musale@inveniolsi.com'
* password = 'Ganesh@2023@'
* ).


CALL METHOD lo_http_client->request->set_method
EXPORTING
method = 'POST'.

**Fill header data
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'application/x-www-form-urlencoded'.
CALL METHOD lo_http_client->request->set_form_field
EXPORTING
name = 'grant_type'
value = 'refresh_token'.

CALL METHOD lo_http_client->request->set_form_field
EXPORTING
name = 'client_id'
value = 'zzzzzzzzzzzzzzzzzzzz'.

CALL METHOD lo_http_client->request->set_form_field
EXPORTING
name = 'client_secret'
value = 'zzzzzzzzzzzzzzzz'.

CALL METHOD lo_http_client->request->set_form_field
EXPORTING
name = 'resource'
value = '00000003-0000-0ff1-ce00-000000000000/invenio12.sharepoint.com@e83d39e6-f19d-49ca-8261-07ae0659a01c'.
CALL METHOD lo_http_client->request->set_form_field
EXPORTING
name = 'refresh_token'
value = 'zzzzzzzzzzzzzzzzzzzzz' &&
'zzzzzzzzzzz'.
lo_http_client->send( ).


lo_http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).

CALL METHOD lo_http_client->response->get_status
IMPORTING
code = lv_code
reason = lv_reason.

*** Read the result
CLEAR lv_result .
* CALL METHOD lo_http_client->response->get_header_field "get_form_field_cs
* EXPORTING
* name = 'access_token'
* RECEIVING
* value = lv_result.
lv_result = lo_http_client->response->get_cdata( ).




CREATE OBJECT lr_instance.

IF lv_result IS NOT INITIAL. "Retrieving your Token here
response = lv_result.

/ui2/cl_json=>deserialize(
EXPORTING
json = response
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
CHANGING
data = m_entries ).

lv_auth2 = m_entries-access_token. "+0(1016).
SHIFT lv_auth2 RIGHT DELETING TRAILING space.
CONDENSE lv_auth2.
response = response+17.

CONCATENATE 'Bearer' lv_auth2 INTO lv_auth SEPARATED BY space. "Using Token Value create your Authorization Code
ENDIF.


CALL METHOD lo_http_client->response->get_raw_message
RECEIVING
data = lv_result1.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_result1
* APPEND_TO_TABLE = ' '
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_binary.

CALL FUNCTION 'SCMS_BINARY_TO_STRING'
EXPORTING
input_length = lv_length
IMPORTING
text_buffer = lv_result
TABLES
binary_tab = lt_binary
EXCEPTIONS
failed = 1
OTHERS = 2.
ENDIF.
lv_url = 'https://zzzzzzzz.sharepoint.com/sites/galaxy/_api/Web/GetFileByServerRelativeUrl(''/sites/galaxy/Accounts/zzzzz_closeAir_Interface/Expenses/Invoice_test1.csv'')/$value'.

CLEAR lo_http_client.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
pse_not_found = 4
pse_not_distrib = 5
pse_errors = 6
oa2c_set_token_error = 7
oa2c_missing_authorization = 8
oa2c_invalid_config = 9
oa2c_invalid_parameters = 10
oa2c_invalid_scope = 11
oa2c_invalid_grant = 12
OTHERS = 13.
IF sy-subrc <> 0.
ENDIF.

lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.

CALL METHOD lo_http_client->request->set_method
EXPORTING
method = 'GET'.

*Fill header data
* CALL METHOD lo_http_client->request->set_header_field
* EXPORTING
* name = 'Content-Type'
* value = 'application/x-www-form-urlencoded'.

CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'application/json; odata=verbose'.

CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Accept'
value = 'application/json; odata=verbose'.

CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Authorization'
value = lv_auth.

lo_http_client->send( ).


lo_http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).

CALL METHOD lo_http_client->response->get_status
IMPORTING
code = lv_code
reason = lv_reason.


***///// Calling file Read API Again
CLEAR lo_http_client.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
pse_not_found = 4
pse_not_distrib = 5
pse_errors = 6
oa2c_set_token_error = 7
oa2c_missing_authorization = 8
oa2c_invalid_config = 9
oa2c_invalid_parameters = 10
oa2c_invalid_scope = 11
oa2c_invalid_grant = 12
OTHERS = 13.
IF sy-subrc <> 0.
ENDIF.

lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.

CALL METHOD lo_http_client->request->set_method
EXPORTING
method = 'GET'.

*Fill header data
* CALL METHOD lo_http_client->request->set_header_field
* EXPORTING
* name = 'Content-Type'
* value = 'application/x-www-form-urlencoded'.

CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Content-Type'
value = 'application/json; odata=verbose'.

CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Accept'
value = 'application/json; odata=verbose'.

CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Authorization'
value = lv_auth.

lo_http_client->send( ).


lo_http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).

CALL METHOD lo_http_client->response->get_status
IMPORTING
code = lv_code
reason = lv_reason.

0 Kudos

I guess you need to check Sharepoint API documentation, how to use it exactly.

You'd better ask in Microsoft-related forums, or Stack Overflow, or things like that.

Possibly, someone working on SAP product may also know.