Skip to main content
Solved

How to capture the response of a RESTful POST request?


hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)

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.

 

Best answer by hhy38

I set a routing rule and a routing address. After that, I wrote this plsql block. It is working now. Thanks Damith and Udesha.

 

DECLARE
    application_message_id_ NUMBER := 0;
    access_token_           VARCHAR2(2000);
    json_data_              VARCHAR2(32000);
    bxml_                   CLOB;
BEGIN
    bxml_ := 'grant_type=password&&username=' || ifsapp.sfn_bt_variable_api.get_degisken_degeri('MEDITEK_WS_KULLANICI_ADI') || '&&password=' ||
             ifsapp.sfn_bt_variable_api.get_degisken_degeri('MEDITEK_WS_SIFRE');
    ifsapp.plsql_rest_sender_api.call_rest_endpoint(rest_service_ => 'MEDITEK_TOKEN', xml_ => bxml_,
                                                    callback_func_ => 'plsql_rest_sender_api.REST_common_callback', http_method_ => 'POST',
                                                    http_req_headers_ => 'Content-Type: application/x-www-form-urlencoded', sender_ => 'IFS',
                                                    subject_ => 'Meditek Token Alma İsteği');
    COMMIT;
    sys.dbms_lock.sleep(3);
    SELECT MAX(t.application_message_id)
    INTO   application_message_id_
    FROM   ifsapp.application_message t
    WHERE  t.state_db = 'Finished'
           AND t.message_function = 'MEDITEK_TOKEN';
    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_);
    ifsapp.sfn_bt_variable_api.Set_Degisken_Degeri('MEDITEK_WS_TOKEN', access_token_);
END;

 

View original
Did this topic help you find an answer to your question?

hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)
  • July 25, 2023

@Lee Pinchbeck @Yasas Kasthuriarachchi @dsj @udlelk @Navinth Bakmeedeniya @Technical Outlaws @Rifki Razick @tobese @Charith Epitawatta @Binura Dodangoda Do you have any suggestions?


Forum|alt.badge.img+14
  • Hero (Employee)
  • July 25, 2023

command_sys.send_rest_message is not the ideal option for your requirement. This is an inbuilt method to be used with REST type Event Actions. 

There is a dedicated API for REST type of integrations which is plsql_rest_sender_api.

Refer: https://docs.ifs.com/techdocs/Foundation1/040_administration/240_integration/300_ifs_connect/010_configure_connect/060_transport_connectors/configure_rest_transport_connector.htm

https://docs.ifs.com/techdocs/Foundation1/050_development/200_all_ref_manuals/api_ref_itd/restapi/default.html


hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)
  • July 25, 2023

I tried this API. I couldn't pass the parameter problem. Because it has 3 different versions of the Call_Rest_EndPoint procedure. Do you have any POST examples?


Forum|alt.badge.img+14
  • Hero (Employee)
  • July 25, 2023

Authentication is handled by IFS Connect itself. You don’t have to get the token and pass it. 

You just have to set the authentication details and the rest endpoint details in the Routing Address Configurations. 

https://docs.ifs.com/techdocs/Foundation1/040_administration/240_integration/300_ifs_connect/010_configure_connect/060_transport_connectors/rest_samples_itd/rest_post_example.htm


hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)
  • July 25, 2023

@udlelk Thank you,

The important part Routing Address. Setting the Routing Rule for Application message is easy. How can I set Routing Address for this scenario.

 

To get access token, we should POST the user name and password in body section. 

 

 

 

 


dsj
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • July 26, 2023

Hi @hhy38 

 

Handling the access token is done by IFS Connect as @udlelk mentioned. You don’t need to implement your own code for that :)

Since your grant type is password, select the Authentication Method as OAuth2.0 ROPC in your routing address and provide user id/password and token endpoint.

 

In your code, use  plsql_rest_sender_API.Call_Rest_EndPoint   to send the POST request.

 

Regards,

Damith


hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)
  • July 26, 2023

Hi Damith @dsj ,

 

The authentication method OAuth2.0 ROPC is not on the list in Routing Address. We have just None, Basic, Bearer and Azure Shared Key. What should we do?

Thank you. :)

 


Forum|alt.badge.img+14
  • Hero (Employee)
  • July 26, 2023

OAuth2.0 Authentication support was added in apps10 UPD6


hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)
  • July 26, 2023

@dsj

By the way, I know ROPC. I am using it to get tokens from IFS. 

 

Here an example:

 

 


hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)
  • July 26, 2023
udlelk wrote:

OAuth2.0 Authentication support was added in apps10 UPD6

@udlelk Thank you. We are using 10.5. So, we have to find another way :)


hhy38
Superhero (Customer)
Forum|alt.badge.img+16
  • Superhero (Customer)
  • August 1, 2023

I set a routing rule and a routing address. After that, I wrote this plsql block. It is working now. Thanks Damith and Udesha.

 

DECLARE
    application_message_id_ NUMBER := 0;
    access_token_           VARCHAR2(2000);
    json_data_              VARCHAR2(32000);
    bxml_                   CLOB;
BEGIN
    bxml_ := 'grant_type=password&&username=' || ifsapp.sfn_bt_variable_api.get_degisken_degeri('MEDITEK_WS_KULLANICI_ADI') || '&&password=' ||
             ifsapp.sfn_bt_variable_api.get_degisken_degeri('MEDITEK_WS_SIFRE');
    ifsapp.plsql_rest_sender_api.call_rest_endpoint(rest_service_ => 'MEDITEK_TOKEN', xml_ => bxml_,
                                                    callback_func_ => 'plsql_rest_sender_api.REST_common_callback', http_method_ => 'POST',
                                                    http_req_headers_ => 'Content-Type: application/x-www-form-urlencoded', sender_ => 'IFS',
                                                    subject_ => 'Meditek Token Alma İsteği');
    COMMIT;
    sys.dbms_lock.sleep(3);
    SELECT MAX(t.application_message_id)
    INTO   application_message_id_
    FROM   ifsapp.application_message t
    WHERE  t.state_db = 'Finished'
           AND t.message_function = 'MEDITEK_TOKEN';
    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_);
    ifsapp.sfn_bt_variable_api.Set_Degisken_Degeri('MEDITEK_WS_TOKEN', access_token_);
END;

 


Forum|alt.badge.img+5
udlelk wrote:

Authentication is handled by IFS Connect itself. You don’t have to get the token and pass it. 

You just have to set the authentication details and the rest endpoint details in the Routing Address Configurations. 

https://docs.ifs.com/techdocs/Foundation1/040_administration/240_integration/300_ifs_connect/010_configure_connect/060_transport_connectors/rest_samples_itd/rest_post_example.htm

Hi @udlelk 

Thanks for the valuable information above.

 

I have this requirement How to combine token generation to use in post outbound request? and wonder

will it be possible to cater this using only one Routing Address without any code change?

 

Like to know your idea/opinion on this.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings