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: 

Is it possible to call an URL with automatic login?

Former Member
0 Kudos

Hello,

how can I call an URL from SAP (with report or fuba) with automatic login?

Example: I call the URL https://appdemo.docusign.com/home

then I have login in Internet Explorer.

Via http_client I can set the Login E-Mail and Password.

I get the response everything is ok. But how can I call the url now.

my Coding:

DATA: lo_http_client     TYPE REF TO if_http_client,
          lv_service         TYPE string,
          lv_result          TYPE string,
          lo_ixml            TYPE REF TO if_ixml,
          lo_streamfactory   TYPE REF TO if_ixml_stream_factory,
          lo_istream         TYPE REF TO if_ixml_istream,
          lo_document        TYPE REF TO if_ixml_document,
          lo_parser          TYPE REF TO if_ixml_parser,
          lo_weather_element TYPE REF TO if_ixml_element,
          lo_weather_nodes   TYPE REF TO if_ixml_node_list,
          lo_curr_node       TYPE REF TO if_ixml_node,
          lv_value           TYPE string,
          lv_node_length     TYPE i,
          lv_node_index      TYPE i,
          lv_node_name       TYPE string,
          lv_node_value      TYPE string.

    lv_service = 'https://demo.docusign.net/xxxxxx'.

    cl_http_client=>create_by_url(
      EXPORTING
        url                = lv_service
      IMPORTING
        client             = lo_http_client
      EXCEPTIONS
        argument_not_found = 1
        plugin_not_active  = 2
        internal_error     = 3
        OTHERS             = 4 ).

    lo_http_client->request->set_method( 'GET' ).
    CALL METHOD lo_http_client->request->set_header_field
      EXPORTING
        name  = 'X-DocuSign-Authentication'
        value = '<DocuSignCredentials><Username>xxxxxxxxx</Username><Password>xxxxxxxxx</Password><IntegratorKey>xxxxxx</IntegratorKey></DocuSignCredentials>'.

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

    lo_http_client->send(
      EXCEPTIONS
        http_communication_failure = 1
        http_invalid_state         = 2 ).

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

    CLEAR lv_result .
    DATA: lv_result_x TYPE xstring.
    lv_result = lo_http_client->response->get_cdata( ).
    lv_result_x = lo_http_client->response->get_data( ).

    DATA: lv_ret_code   TYPE i,
          lv_err_string TYPE string.
    lo_http_client->response->get_status(
      IMPORTING
        code   = lv_ret_code
        reason = lv_err_string       ).  "here lv_err_string = OK
7 REPLIES 7

Domi
Contributor

Hi

Just set the API Url and send the request - the authentication info is either stored in a cookie (will be sent automatically) or you need to set some header field or GET/POST parameter

lo_http_client->refresh_request( EXCEPTIONS http_action_failed = 1
                                            OTHERS             = 2 ).
IF sy-subrc <> 0.
  "Error Handling
ENDIF.

cl_http_utility=>set_request_uri( request = lo_http_client->request uri = 'API URL' ).

lo_http_client->send( EXCEPTIONS http_communication_failure = 1
                                 http_invalid_state         = 2
                                 OTHERS                     = 3 ).
IF sy-subrc <> 0.
  "Error Handling
ENDIF.

regards

Domi

Former Member
0 Kudos

How can I get here the url from response and call it with CALL_BROWSER?

Hi

This is part of the API - I know some of them, but definitely not all!

Just get the AUTH token and provide it with the next call (e.g. with method CL_GUI_HTML_VIEWER->SHOW_URL_IN_BROWSER)

And please: RTFM

regards

Domi

matt
Active Contributor

Create a destination in SM59, with the credentials for login. Then use cl_http_client=>create_by_destination to get your client.

See here for details https://blogs.sap.com/2014/11/09/calling-an-external-restful-service-from-abap-http-method-get/

Former Member
0 Kudos

I tried and can not call the url on ie.

matt
Active Contributor
0 Kudos

Sorry. Thought you were consuming a webservice. Didn't realise you actually want a browser session.

Sandra_Rossi
Active Contributor
0 Kudos

Please post a new question (CALL_BROWSER automatic login via HTTPS), as it's different from your original question (automatic login via CL_HTTP_CLIENT)