cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP issues during simple call to external API using SAP ABAP

ricky_shaw
Contributor
0 Kudos
950

Hi,

I am trying to use the API's for Airport locations. The API is from : https://airport-info.p.rapidapi.com/

I had written the code in ABAP(SE38) as below: 

In my code, I had created the  HTTP Object using cl_http_client=>create_by_url 

 

 

 Report ZAPITEST.
 
    DATA: lv_url   TYPE string,
          o_client TYPE REF TO if_http_client.

    lv_url = |https://airport-info.p.rapidapi.com/airport?iata=IAH&icao=%20| .


**Create HTTP Object
    cl_http_client=>create_by_url( EXPORTING  url = lv_url
                                  IMPORTING   client = o_client
                                  EXCEPTIONS
                                      argument_not_found = 1
                                      plugin_not_active = 2
                                      internal_error = 3
                                  OTHERS = 4 ).

    IF sy-subrc NE 0.
      o_client->close( ).
    ENDIF.

    IF o_client IS BOUND.

**set HTTP method
      o_client->request->set_method( if_http_request=>co_request_method_get ).

**Set header fields


      o_client->request->set_header_field( name  = 'x-rapidapi-host'
                                           value = 'airport-info.p.rapidapi.com' ).


      o_client->request->set_header_field( name  = 'x-rapidapi-key'
                                           value = 'bc72402653msh7b2eecfeed81753p17fc71jsn7b1c02627865' ).

**Set time out
*      o_client->send( timeout = if_http_client=>co_timeout_default ).
       o_client->send( EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state        = 2 ).

** read response, http Status , Payload
      o_client->receive( EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state = 2
      http_processing_failed = 3
      OTHERS = 4 ).

      DATA: lv_http_status TYPE i,
            lv_status_text TYPE string.

      o_client->response->get_status( IMPORTING code = lv_http_status
                                    reason = lv_status_text ).

      WRITE : / 'HTTP Status code :', lv_http_status,
                'Status Text : ', lv_status_text.

      IF lv_http_status = 200.
        DATA(lv_result) = o_client->response->get_data( ).
        WRITE : / 'Response :',  lv_result.

      ENDIF.
** Close http connection
      o_client->close( ).
    ENDIF.
 

 

During receive, it's throwing an  HTTP error because of some "NIECONN_REFUSED(-10)" & not due to certificate. 

I am on Zscalar VPN connection.

How to solve this? What settings should i fix? 

View Entire Topic
Azeemquadri
Contributor
0 Kudos

Is it working with postman. Check smicm logs also.

ricky_shaw
Contributor
0 Kudos
ok. When i run my ABAP prog its showing status code as 400 & Connection refused
ricky_shaw
Contributor
0 Kudos
Yes its working via Postman. Whats the use of SMICM log here?
Azeemquadri
Contributor
These logs will confirm if the connection is refused due to a firewall. Send the smicm logs to your network team. Maybe you need a proxy to communicate with the API. Check sm59 for a proxy. You can use the same proxy credentials to connect.
ricky_shaw
Contributor
0 Kudos
Hi Azeemquadri, I created a test connection in SM59 for External HTTP (G type) but it says connection failed.I mentioned host name : airport-info.p.rapidapi.com What are other params that i need to pass? Whats the path prefix should i use?
Azeemquadri
Contributor
0 Kudos
" Set proxy details o_client->set_proxy( host = lv_proxy_host port = lv_proxy_port ). You can check if there is a proxy used for your system in SM59 top menu. Or ask basis to help with proxy details.
ricky_shaw
Contributor
0 Kudos
I don't see any set_proxy( ) method here..can you pls check
ricky_shaw
Contributor
0 Kudos
i mean set_proxy( ) method is not found