We made use of utl_http to post json_data. This piece of code will help in sending data to Custom Applications

DECLARE

   vrequest                                  CLOB;

   oresp_status_code                VARCHAR2 (32000);

   oresp_reason_phrase           VARCHAR2 (32000);

   vurl                                            VARCHAR2 (32000);

   oresponse                                  VARCHAR2 (2000);

   http_request                            UTL_HTTP.req;

   http_response                           UTL_HTTP.resp;

   v_detailed_error_message      VARCHAR2 (32000);

   x_validation_status                   VARCHAR2 (32000);

   vwhere                                         VARCHAR2 (10);

   vurl_connect                               VARCHAR2 (32000);

   vrequest_connect                      VARCHAR2 (32000);

   vresponse_clob                              CLOB;

   vresponse                                        VARCHAR2 (32767);

   vresp_status_code                        VARCHAR2 (32000);

   vresp_reason_phrase                   VARCHAR2 (32000);

   l_bearer_value                               VARCHAR2 (32000);

   l_application_key                           VARCHAR2 (32000)   := ‘xxxx’;

   l_bearer_token                               VARCHAR2 (4000);

   dbname                                            VARCHAR2 (100);

   lv_c_json                                          VARCHAR2 (3000);

   lv_c_jason                                       CLOB;

   lv_c_json1                                       CLOB;

   lv_c_json_str                                  CLOB;

   lv_c                                                  CLOB;

   lv_c1                                               CLOB;

   lv_c2                                               CLOB;

   total_ord                                       NUMBER;

BEGIN

   lv_c_json1 :=

      ‘{

    “entity”: {

        “entity_id”: “2738”,

        “status”: “processing”,

        “state”: “processing”,

        “extension_attributes”: {

            “oracle_order_id”: “34471422”,

            “oracle_shipment_tracking_number”: “987651”

        }

    }

}’;

   vrequest := lv_c_json1;

   UTL_HTTP.set_wallet (‘file:/home/oracle/wallets’, ‘n3wm00n!’);

   vurl := ‘https://abc.com/xxx/xxxxx’;  —URL To post the Json Data

   http_request := UTL_HTTP.begin_request (vurl, ‘POST’, ‘HTTP/1.1’);

   SELECT ‘Bearer ‘ || l_application_key

     INTO l_bearer_value

     FROM DUAL;

 

   UTL_HTTP.set_header (http_request, ‘Connection’, ‘keep-alive’);

   UTL_HTTP.set_header (http_request, ‘Authorization’, l_bearer_value);

   UTL_HTTP.set_header (http_request, ‘Content-Type’, ‘application/json’);

   UTL_HTTP.set_header (http_request, ‘x-ccasset-language’, ‘en’);

   UTL_HTTP.set_header (http_request, ‘Content-Length’, LENGTH (vrequest));

   UTL_HTTP.write_text (http_request, vrequest);

   http_response := UTL_HTTP.get_response (http_request);

 

   IF http_response.status_code IS NOT NULL

   THEN

      vresp_status_code := http_response.status_code;

   END IF;

   IF http_response.reason_phrase IS NOT NULL

   THEN

      vresp_reason_phrase := http_response.reason_phrase;

   END IF;

   UTL_HTTP.read_text (http_response, vresponse, 32766);

   UTL_HTTP.end_response (http_response);

   oresponse := SUBSTR (vresponse, 1, 2000);

   oresp_status_code := SUBSTR (vresp_status_code, 1, 2000);

   oresp_reason_phrase := SUBSTR (vresp_reason_phrase, 1, 2000);

   UTL_HTTP.end_request (http_request);

END;

Recent Posts

Start typing and press Enter to search