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.

Oracle Apex make_rest_request function returning 401 Unauthorized after generating IDCS client credential token

Parul_ORAJan 24 2025 — edited Jan 24 2025

Hi Team,

My question is about the challenge which I am facing while Calling Oracle Fusion (Cloud- v24D) Purchase requisition Rest API from Oracle Apex (Cloud- v24.1) make_rest_request function using GET method.
I wanted to establish Oauth2.0 Authentication using Oracle IAM(IDCS) to generate Token based on client_credential grant type.
I am using APEX_WEB_SERVICE.OAUTH_AUTHENTICATE and passing token,Client_ID, Client_secret and scope.
While calling this plsql code I am able to get IDCS token and post that receiving 401 Unauthorized error in make_rest_request clob response.
This API is working perfectly with Basic authentication scheme using the similar plsql code, and returning 200 ok, that means my fusion account is having all required roles to call API.
I am not sure if its specific to any setup enablement between Fusion and Apex?

Please find sample code below:

Please help me. Thanks in advance..!!

declare
   l_json_clob1     CLOB;
   l_req_itemdesc_url     VARCHAR2(200);
   lc_get_header_cnt  NUMBER := 0;
   lv_response_code  NUMBER;
   v_response_phrase varchar2(1000);
   v_token varchar2(4000);
   l_err_msg varchar2(2000);
   BEGIN
  -- Construct URL using the fetched server path
   l_req_itemdesc_url := 'https://FAServer.fa.ocs.oraclecloud.com:443/fscmRestApi/resources/11.13.18.05/purchaseRequisitions/passing_purchase_req_id/child/lines';
    apex_web_service.g_request_headers.DELETE;
   APEX_WEB_SERVICE.OAUTH_AUTHENTICATE(
   p_token_url      => 'https://IDCS.identity.oraclecloud.com/oauth2/v1/token',
   p_client_id      => '1234',
   p_client_secret  => 'abcd',
   p_scope          => 'https://fascope.fa.ocs.oraclecloud.com:443/'
   );
   apex_web_service.g_request_headers(1).name := 'Authorization';
   apex_web_service.g_request_headers(1).value := 'Bearer ' || apex_web_service.oauth_get_last_token;
   apex_web_service.g_request_headers(2).name := 'Content-Type';
   apex_web_service.g_request_headers(2).value := 'application/json';
   select apex_web_service.oauth_get_last_token into v_token from dual;
   dbms_output.put_line ('v_token: '||v_token);
   
     l_json_clob1 := apex_web_service.make_rest_request
                      (p_url         => l_req_itemdesc_url,
                       p_http_method => 'GET' 
                       );
   lv_response_code := apex_web_service.g_status_code;
   v_response_phrase := APEX_WEB_SERVICE.G_REASON_PHRASE;
   dbms_output.put_line('lv_response_code1: '||lv_response_code);
   dbms_output.put_line('v_response_phrase1:'||v_response_phrase);
   dbms_output.put_line('l_json_clob1 :'||l_json_clob1);
   Exception
   WHEN OTHERS THEN
   dbms_output.put_line('Main exception: '||SQLERRM);
   END;
   
Comments
Post Details
Added on Jan 24 2025
3 comments
398 views