Skip to Main Content

SQL & PL/SQL

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!

Calling a rest service from PL/SQL

Igor SDec 19 2023

Dear Oracle community,

I keep getting a error “Missing form parameter: grant_type” every time I call my procedure and I cant figure out what I am doing wrong. Database version is 12c (12.2.0.1.0). The rest service is using OAuth 2 authorization and call from postman is working:

declare
  req          utl_http.req;
  res          utl_http.resp;
  url          varchar2 (500);
  granttype    varchar2 (100) := 'client_credentials'; -- Specify your grant type
  clientid     varchar2 (100) := 'your_client_id';
  secret       varchar2 (100) := 'your_client_secret';
  params       varchar2 (500);
  responsebody clob;
begin
  url    := 'https://example.com/token_endpoint'; -- Replace with your endpoint

  params := 'grant_type=' || utl_url.escape (granttype) || '&client_id=' || utl_url.escape (clientid) || '&client_secret=' || utl_url.escape (secret);

  req    := utl_http.begin_request (url, 'POST', utl_http.http_version_1_1);
  utl_http.set_header (req, 'Content-Type', 'application/x-www-form-urlencoded');
  utl_http.set_body_charset (req, 'UTF-8');

  utl_http.write_text (req, params);

  res    := utl_http.get_response (req);

  utl_http.read_text (res, responsebody);
  dbms_output.put_line (responsebody);

  utl_http.end_response (res);
exception
  when utl_http.end_of_body
  then
    utl_http.end_response (res);
end;
/
Comments
Post Details
Added on Dec 19 2023
7 comments
2,444 views