Hi,
I am trying to integrate IFS with another system. I will send the data. Before that, I need to get the access token of the web service. So, I am sending a POST request with the “command_sys.send_rest_message” procedure. The procedure doesn’t give a response body. And also the procedure has no out parameter like application message id. (at least plsqlap_server_api.post_outbound_bizapi procedure has out parameter application message id :)) So, I tried to capture the access token in a weird way(You can see the code below. ). I searched message value on application messages (inside the last 1 minute) with the message text. This is not a good way to get an access token. I think it won’t work sometime. Is there a better way to get the access token?
DECLARE
rest_sender_ VARCHAR2(2000) := 'REST_SENDER1';
end_point_ VARCHAR2(2000);
auth_method_ VARCHAR2(2000);
http_method_ VARCHAR2(10) := 'POST'; -- get or post both are working.
query_params_ VARCHAR2(32000);
header_params_ VARCHAR2(32000);
login_info_ VARCHAR2(32000);
rest_message_ CLOB;
url_params_ VARCHAR2(32000);
blob_info_ VARCHAR2(32000);
bot_token_ VARCHAR2(2000);
chat_id_ VARCHAR2(2000);
text_ VARCHAR2(32000) := '';
application_message_id_ NUMBER := 0;
access_token_ VARCHAR2(2000);
json_data_ VARCHAR2(32000);
BEGIN
end_point_ := 'https://xxx.yyy.com/isg/token';
rest_message_ := 'grant_type=password&&username=aaaa&&password=bbbb';
command_sys.send_rest_message(rest_message_, end_point_, auth_method_, login_info_, rest_sender_, header_params_, url_params_, http_method_, blob_info_,
query_params_);
COMMIT;
sys.dbms_lock.sleep(3);
SELECT mb.application_message_id
INTO application_message_id_
FROM ifsapp.message_body mb
WHERE mb.application_message_id IN (SELECT t.application_message_id
FROM ifsapp.application_message t
WHERE t.created_by = 'IFSAPP'
AND t.sender = 'PROD'
AND t.receiver = 'CONNECT'
AND t.message_type = 'EVENT'
AND t.created_date > SYSDATE - 1 / 1440)
AND mb.seq_no = 1
AND dbms_lob.substr(mb.message_text, length('grant_type=password')) = 'grant_type=password';
SELECT m.message_value
INTO json_data_
FROM ifsapp.message_body m
WHERE m.application_message_id = application_message_id_
AND m.seq_no = 2;
access_token_ := json_value(json_data_, '$.access_token');
dbms_output.put_line('Access Token: ' || access_token_);
END;
The output of the code.