I am confused about utl_http and oauth authentication with shopware 6. I undestand I have to obtain a token, which has to be used in futher requests. With all efforts I am getting the answer: "The authorization grant type is not supported by the authorization server".
There is tons of info on this issue but very little with utl_http - so i wonder if utl_http is comaptible with shopware anyway. Does anybody have a hint for me? thanks in advance!
l_req UTL_HTTP.req;
l_resp UTL_HTTP.resp;
l_text VARCHAR2(32767);
begin
-- setting the Wallet works - ACL is also set up properly!
utl_http.set_wallet('[wallet_file]','[wallet_pwaasword]');
l_req := UTL_HTTP.begin_request([my-shopware-url.de]/api/oauth/token], 'POST', 'HTTP/1.1');
utl_http.set_header(l_req, 'content-type', 'application/json');
utl_http.set_header(l_req, 'Accept', 'application/json');
utl_http.write_text(l_req,'{
"grant_type": "client_credentials",
"client_id": "[my-client-id]",
"client_secret": "[my-client-secret]"
}');
l_resp := utl_http.get_response(l_req);
utl_http.read_text(l_resp, l_text, 32766);
DBMS_OUTPUT.put_line (l_text); -- "The authorization grant type is not supported by the authorization server".
-- once the token is obtained, I would set the token in the header for the next request
utl_http.set_header(l_req, 'sw-access-key', [TOKEN]);
utl_http.write_text(l_req,'[REQUEST-BODY]');
l_resp := utl_http.get_response(l_req);
utl_http.end_response(l_resp);
end;

utl_http is a low level tool to make REST requests. It will definitly work but you have to figure it out. I have always struggled with it.
Here you are sending some parameters as a json text:
I doubt this will work...
What about using apex_web_service.make_rest_request as an alternative ?
Here is an example :
I have no idea what shopware is but If you want to send grant_type, client_id and client_secret, you can either try send them in Headers. It this doesn't work, you can send them in parameters. One of them will work.