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: 

SAP Cloud Identity Services oData call from ABAP

363
  • SAP Managed Tags:

Hi,

I need to develop a call of put/post method called from SAP Abap system in order to insert new users into the user Groups of SAP CIS ( here there are information about what I am referring to ), so for the moment I have developed this:

REPORT ztest_rfc.

DATA: lo_http_client TYPE REF TO if_http_client,
      lo_rest_client TYPE REF TO cl_rest_http_client,
      lv_url(12)     TYPE c,
      lv_url1        TYPE string,
      http_status    TYPE string,
      lv_body        TYPE string.

DATA: lo_json        TYPE REF TO cl_clb_parse_json,
      lo_response    TYPE REF TO if_rest_entity,
      lo_request     TYPE REF TO if_rest_entity,
      lo_sql         TYPE REF TO cx_sy_open_sql_db,
      status         TYPE string,
      reason         TYPE string,
      response       TYPE string,
      content_length TYPE string,
      location       TYPE string,
      content_type   TYPE string,
      lv_status      TYPE i.

lv_url = 'IAS_REST_API'.
cl_http_client=>create_by_destination(
  EXPORTING
    destination              = lv_url                
  IMPORTING
    client                   = lo_http_client             
  EXCEPTIONS
    argument_not_found       = 1              
    destination_not_found    = 2                " Destination not found
    destination_no_authority = 3                " No Authorization to Use HTTP Destination
    plugin_not_active        = 4                " HTTP/HTTPS communication not available
    internal_error           = 5                " Internal error (e.g. name too long)
    others                   = 6
).

lo_http_client->request->set_version( if_http_request=>co_protocol_version_1_0 ).

IF lo_http_client IS BOUND.

  lv_body = '{ "id" : "607xxxxxxxxx", "displayName" : "Admin", "members" : [{ "value" : "P000001" }] }'.
  lo_request = lo_rest_client->if_rest_client~create_request_entity( ).
  lo_request->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
  lo_request->set_string_data( lv_body ).
  lo_http_client->request->set_method( if_http_request=>co_request_method_post ).

CALL METHOD lo_rest_client->if_rest_client~set_request_header
 EXPORTING
   iv_name  = 'Content-Type'
   iv_value = 'application/scim+json'. "Set your header .

  lo_rest_client->if_rest_resource~put( lo_request ).
* Collect response

  lo_response    = lo_rest_client->if_rest_client~get_response_entity( ).
  http_status    = lv_status = lo_response->get_header_field( '~status_code' ).
  reason         = lo_response->get_header_field( '~status_reason' ).
  content_length = lo_response->get_header_field( 'content-length' ).
  location       = lo_response->get_header_field( 'location' ).
  content_type   = lo_response->get_header_field( 'content-type' ).
  response       = lo_response->get_string_data( ).

ENDIF.

So my problem is the program in the end is giving me an '400' error 'Bad request'. I wonder some ways could be incomplete my code but I don't know how to solve it.

Some suggestions?

Thanks in advance.

1 REPLY 1

LuizGomes
Participant
0 Kudos
134
  • SAP Managed Tags:

news ?