Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to second api call in oracle apex

Ajith Ram6 days ago — edited 5 days ago

DECLARE
l_token_response CLOB;
l_access_token VARCHAR2(4000);
l_response CLOB;
l_username VARCHAR2(100);
l_password VARCHAR2(100);
l_body CLOB;
l_bodys CLOB;
l_json_response JSON_OBJECT_T;
BEGIN
-- Get username and password from APEX Page Items
l_username := V('P701_USERNAME');
l_password := V('P701_PASSWORD');

-- Construct JSON Body for Authentication
l_body := '{"username": "' || l_username || '", "password": "' || l_password || '"}';

-- Set Headers for Token Request
apex_web_service.g_request_headers(1).name := 'Content-Type';
apex_web_service.g_request_headers(1).value := 'application/json';
apex_web_service.g_request_headers(2).name := 'app-id';
apex_web_service.g_request_headers(2).value := 'xxxxxx';
apex_web_service.g_request_headers(3).name := 'app-key';
apex_web_service.g_request_headers(3).value := 'yyyyyyy';

-- Call API to Get Token
BEGIN
l_token_response := APEX_WEB_SERVICE.MAKE_REST_REQUEST(
p_url => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
p_http_method => 'POST',
p_body => l_body,
p_transfer_timeout => '60',
p_wallet_path => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
p_wallet_pwd => 'yyyyyyyy');

-- Store Access Token in APEX Session
APEX_UTIL.SET_SESSION_STATE('P701_API_RESPONSE', l_token_response);
DBMS_OUTPUT.PUT_LINE('Access Token Received: ' || l_token_response);
EXCEPTION WHEN OTHERS THEN NULL;

-- Check if access token is available
IF l_token_response IS NOT NULL THEN
-- Construct JSON Body for Second API Call
--,
l_bodys := '{
"iqamaNumber": "2123123123",
"visaDuration": 7,
"visaType": 1}';

   -- Reset Headers Before Setting New Ones  
   apex\_web\_service.g\_request\_headers(1).name  := 'Content-Type';  
   apex\_web\_service.g\_request\_headers(1).value := 'application/json';  
   apex\_web\_service.g\_request\_headers(2).name  := 'app-id';  
   apex\_web\_service.g\_request\_headers(2).value := 'xxxxxxx';  
   apex\_web\_service.g\_request\_headers(3).name  := 'app-key';  
   apex\_web\_service.g\_request\_headers(3).value := 'yyyyyyyyyyy';  
   apex\_web\_service.g\_request\_headers(4).name  := 'Authorization';  
   apex\_web\_service.g\_request\_headers(4).value := 'Bearer'||l\_token\_response;

   -- Call API with Token  
   BEGIN  
       l\_response := APEX\_WEB\_SERVICE.MAKE\_REST\_REQUEST(  
           p\_url         => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',    
           p\_http\_method => 'POST',  
           p\_body        => l\_body,  
           p\_transfer\_timeout => '60',  
           p\_wallet\_path => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',  
           p\_wallet\_pwd  => 'yyyyyyyyyyyyy');

       -- Store API Response in APEX Session  
       APEX\_UTIL.SET\_SESSION\_STATE('P701\_RESPONSE', l\_response);  
       DBMS\_OUTPUT.PUT\_LINE('Final API Response: ' || DBMS\_LOB.SUBSTR(l\_response, 4000, 1));  
       EXCEPTION WHEN OTHERS THEN  DBMS\_OUTPUT.PUT\_LINE('Error in second API call: ' || SQLERRM);  
   END;  

ELSE
DBMS_OUTPUT.PUT_LINE('No access token received, second API call skipped.');
END IF;

END;
END;

Hi team,I received a response token. In the first call, I get the token ID, but in the second call, the API does not return a response.
In Postman, the second API call works, but it is not working in my code.Please guide me.

Comments
Post Details
Added 6 days ago
0 comments
33 views