Application Development and Automation 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: 

Get Data from https://smard.api.bund.dev/ not working (complete ABAP-Code is in post)

mariomueller68
Explorer
0 Kudos
358

Good morning,

I have to code some ABAP to receive data from https://smard.api.bund.dev/

For my first attemped I used the URL "https://smard.api.proxy.bund.dev/app/chart_data/1223/DE/index_hour.json"

When I use this URL in the browser I see/getmariomueller68_1-1741669507050.png

 

 

I created a SM59 connection:mariomueller68_0-1741669374189.png

 

 

My code is:

 

  DATA: lo_http_client TYPE REF TO if_http_client,
        lv_url         TYPE        string.


  cl_http_client=>create_by_destination(
      EXPORTING
          destination = 'BUNDESNETZAGENTURSTROMMARKTDATEN'
      IMPORTING
          client = lo_http_client " HTTP Client object
      EXCEPTIONS
           argument_not_found = 1
           destination_not_found = 2
           destination_no_authority = 3
           plugin_not_active = 4
           internal_error = 5
           OTHERS = 6 ).

  lo_http_client->request->set_method( if_http_request=>co_request_method_post ).
  lo_http_client->request->set_version( if_http_request=>co_protocol_version_1_1 ).
  lv_url =
  '/app/chart_data/1223/DE/index_hour.json'.

  CALL METHOD cl_http_utility=>set_request_uri
    EXPORTING
      request = lo_http_client->request
      uri     = lv_url.


  lo_http_client->request->set_content_type( 'application/json' ).
  CALL METHOD lo_http_client->send "sending request to api
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

  CALL METHOD lo_http_client->receive "receiving response from api
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.

  DATA:
*        http_status TYPE string,
        reason      TYPE string,
        response    TYPE string.

  CALL METHOD lo_http_client->response->get_status
    IMPORTING
      code   = data(http_status)
      reason = reason.

  response = lo_http_client->response->get_cdata( ).
*  cl_demo_output=>display_json( json = json_response ).
  cl_demo_output=>display_text( text =  response ).

 

But my ABAP Code displays only:mariomueller68_2-1741669569203.png

 

What I am doing wrong

 

 

 

 
 

 

 

5 REPLIES 5

M-K
Active Participant
268

Hi, check the HTTP Method (use GET instead of POST in ABAP).

 

0 Kudos
219

Hi M-K,

thx for the reply. But this did not solve the issue 😞

thanks regards,

Mario

ulrich_mhrke
Explorer
182

I would try to use method get_data instead of get_cdata on line 51.

mariomueller68
Explorer
0 Kudos
140

Hi Ulrich,

many thanks. Looks much better but not 100% 🙂

mariomueller68_0-1743479923956.png

But when I put the URL

https://smard.api.proxy.bund.dev/app/chart_data/1223/DE/index_hour.json

in the Browser I get:

mariomueller68_1-1743479965551.png

What am I doing wrong?

thanks regards,

Mario

 

 

 

 

 

ulrich_mhrke
Explorer
0 Kudos
97

The data you get from get_cdata is binary data. You have to translate it into your program internal data.

First you can translate it into readable data to see that you have the right data, for instance using method CL_BINARY_CONVERT=>XSTRING_UTF8_TO_STRING.

You can map the binary data using "CALL TRANSFORMATION" to program internal data. Maybe a "Simple Transformation" does the job for you (https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenabap_st.htm).

Or use the sXML library to analyze the data (https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenabap_sxml_lib.htm).

There may be other ways to analyze the json data.