hxxxrz

Untitled

Apr 5th, 2022 (edited)
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 2.21 KB | None | 0 0
  1. REPORT z_sva_test_fedorov.
  2.  
  3. DATA: lv_body      TYPE string,
  4.       lv_body2     TYPE string,
  5.       lv_body_date TYPE string,
  6.       lv_body_rate TYPE string VALUE '3'.
  7.  
  8. DATA: lo_client      TYPE REF TO if_http_client,
  9.       lo_rest_client TYPE REF TO cl_rest_http_client.
  10. *
  11. *
  12. **     call_WS_data_currency
  13.  
  14. DATA(lv_url) = |https://integration.ekvio.ru/v3/users/sync|.
  15.  
  16. cl_http_client=>create_by_url(
  17.   EXPORTING
  18.       url    = lv_url
  19.       ssl_id = 'ANONYM'
  20.   IMPORTING
  21.       client = lo_client
  22.   EXCEPTIONS
  23.       argument_not_found = 1
  24.       internal_error     = 2
  25.       plugin_not_active  = 3 ).
  26.  
  27. IF sy-subrc IS NOT INITIAL.
  28.  
  29.   lo_client->get_last_error(
  30.     IMPORTING
  31.         message = DATA(lv_error_text) ).
  32.  
  33. ENDIF.
  34. *
  35. *
  36. CREATE OBJECT lo_rest_client " создали клиента
  37.   EXPORTING
  38.     io_http_client = lo_client.
  39.  
  40. *
  41. lo_client->request->set_version( if_http_request=>co_protocol_version_1_1 ). " параметры
  42.  
  43. ******* rest body
  44.  
  45. DATA(lo_request) = lo_rest_client->if_rest_client~create_request_entity( ).
  46.  
  47. lo_request->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
  48.  
  49. lo_request->set_header_field(
  50.   EXPORTING
  51.     iv_name  = 'Authorization'
  52.     iv_value = |Bearer 0WvhXXMx4ePpAFN46aHjReSLGsu5HQCF| ).
  53.  
  54.  
  55. lv_body = '{"data": [ { "login": "petrov_iv", "password": "password123456", "first_name": "Ivan", "last_name": "Ivan", "email": "[email protected]", "phone": "79275222222", "chief_email": "[email protected]",' &&
  56.           '"status": "active", "invited": true } ], "partial_sync": true, "chief_sync": true, "notify_users": true, "with_whitelist": true }'.
  57.  
  58. lo_request->set_string_data( lv_body ).
  59.  
  60.  
  61. ******* post
  62.  
  63. TRY.
  64.     lo_rest_client->if_rest_resource~post( io_entity = lo_request ).."( lo_request ).
  65.  
  66.     DATA(lo_response) = lo_rest_client->if_rest_client~get_response_entity( ).
  67.  
  68.     DATA(lv_http_status) = lo_response->get_header_field( '~status_code' ).
  69.  
  70.     DATA(lv_test) = lo_response->get_string_data( ).
  71.  
  72.   CATCH cx_rest_client_exception INTO DATA(lo_exception).
  73.     DATA(lv_msg) = `HTTP POST failed: ` && lo_exception->get_text( ).
  74. ENDTRY.
  75.  
  76. IF lo_rest_client IS BOUND   .
  77.   lo_rest_client->if_rest_client~close( ).
  78. ENDIF.
Add Comment
Please, Sign In to add comment