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!

apex_web_service.make_rest_request returns nothing....

Geert01Nov 30 2021 — edited Dec 9 2021

All I want to do is the equivilent of the following curl command
curl --location --request POST 'https://api.meethue.com/oauth2/refresh?grant_type=refresh_token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic xxxxxxxxxxxx' \
--data-raw 'refresh_token=yyyyyyyyyy'
but every time I execute:
declare
l_secret varchar2(100);
l_client_id varchar2(200);
l_refresh_token varchar2(200);
l_creds varchar2(200);
l_client_creds varchar2(200);
l_req_body clob;
l_result clob;
begin
l_refresh_token := 'xxxxxx';
l_client_id := 'yyyyyy';
l_secret := 'zzzzzzzz';
l_creds := l_client_id||':'||l_secret; --Client credentials unencoded
l_client_creds :=replace(replace(replace(utl_encode.text_encode(l_creds,'WE8ISO8859P1', UTL_ENCODE.BASE64),chr(9)),chr(10)),chr(13)); -- BASE64 - encodes credentials
apex_web_service.g_request_headers(1).name := 'Authorization';
apex_web_service.g_request_headers(1).value := 'Basic '||l_client_creds;
apex_web_service.g_request_headers(2).name := 'Content-Type';
apex_web_service.g_request_headers(2).value := 'application/x-www-form-urlencoded';
--l_req_body := 'refresh_token='||l_refresh_token;
l_req_body := '{"refresh_token": "||l_refresh_token||'"}' ;
l_result := apex_web_service.make_rest_request
( p_url => 'https://api.meethue.com/oauth2/refresh?grant_type=refresh_token'
, p_body => l_req_body
, p_http_method => 'POST'
);
dbms_output.put_line( l_result );
end;

I get nothing back.
The only thing I am not sure of is the way l_req_body should be defined.
image.png

I have exeperimented with casting it to raw using
l_req_body_raw := UTL_RAW.CAST_TO_RAW('refresh_token:'||l_refresh_token);
and also using
apex_json.initialize_clob_output ();
apex_json.open_object ();
apex_json.write ('refresh_token', l_refresh_token);
apex_json.close_all ();
l_req_body := apex_json.get_clob_output ();
apex_json.free_output ();
But nothing I do gets me the refresh token I need.
Using the curl command, and Postman gives me the result I am looking for. So the rest-api is working and returning values.I just cannot get it working in pl/sql

What am I doing wrong?

This post has been answered by Geert01 on Dec 13 2021
Jump to Answer
Comments
Post Details
Added on Nov 30 2021
5 comments
1,803 views