For a simple REST call, Integration Broker typically requires the creation and configuration of multiple metadata components—Messages, Services, Service Operations, Routings, and Handlers.
The IB_GENERIC service acts as a generic wrapper that enables REST calls without requiring custom service definitions.
IB_GENERIC is delivered by PeopleSoft, it is already registered, secured, and available for use in most environments—significantly reducing setup time.
The ConnectorRequest method is the most commonly used approach when developers want to invoke a REST API directly from PeopleCode. It allows you to:
-
Specify the target URL dynamically
-
Set HTTP methods (GET, POST, PUT, DELETE, etc.)
-
Pass request headers and payloads
-
Receive the response as a string or message object
This example demonstrates how to send an SMS using a third-party REST API directly from PeopleCode without creating any Integration Broker metadata (Service, Operation, Routing, etc.).
The call is executed using the delivered IB_GENERIC service and the %IntBroker.ConnectorRequest method.
Function sendTextSMS(&messageText As string, &number As string)
Local Message &RequestSMS, &ResponseSMS;
Local boolean &bSMS;
Local string &jsonPayload, &jsonResponse;
Local JsonObject &jsonSMS;
Local JsonParser &parserSMS;
Local boolean &retSMS;
Local JsonObject &jsonRootSMS;
Local Record &LogTable;
Local string &apiKey = "123test123"; /* API Key */
try
/* Remove CR/LF */
&messageText = Substitute(&messageText, Char(10), " ");
&messageText = Substitute(&messageText, Char(13), " ");
&messageText = LTrim(RTrim(&messageText));
/* Create JSON Payload */
&jsonSMS = CreateJsonObject();
/* Multiple numbers should be separated by ';'
Example:
9665xxxxxxx;9665yyyyyyy
*/
&jsonSMS.AddProperty("mobile_numbers", &number);
&jsonSMS.AddProperty("msg", &messageText);
&jsonPayload = &jsonSMS.ToString();
/* Create HTTP Request */
&RequestSMS = CreateMessage(Message.IB_GENERIC);
&RequestSMS.IBInfo.IBConnectorInfo.ConnectorName = "HTTPTARGET";
&RequestSMS.IBInfo.IBConnectorInfo.ConnectorClassName = "HttpTargetConnector";
/* HTTP Method */
&bSMS = &RequestSMS.IBInfo.IBConnectorInfo.AddConnectorProperties("Method", "POST", %HttpProperty);
/* New API URL */
&bSMS = &RequestSMS.IBInfo.IBConnectorInfo.AddConnectorProperties("URL", "https://api.kk.edu.fa/Hub/api/v1/SMS/Send", %HttpProperty);
/* Required Headers */
&bSMS = &RequestSMS.IBInfo.IBConnectorInfo.AddConnectorProperties("X-API-KEY", &apiKey, %Header);
&bSMS = &RequestSMS.IBInfo.IBConnectorInfo.AddConnectorProperties("Content-Type", "application/json", %Header);
/* Set Body */
&bSMS = &RequestSMS.SetContentString(&jsonPayload);
/* Send */
&ResponseSMS = %IntBroker.ConnectorRequest(&RequestSMS, True);
&jsonResponse = &ResponseSMS.GetContentString();
/* Parse Response */
&parserSMS = CreateJsonParser();
If &parserSMS.Parse(&jsonResponse) Then
&jsonRootSMS = &parserSMS.GetRootObject();
End-If;
/************************************************
Adjust the success condition depending on
the API response.
************************************************/
catch Exception &ex
MessageBox(0, "", 0, 0, "Error occurred while sending SMS: " | &ex.ToString());
end-try;
End-Function;
Local boolean &smsSent;
Local string &mobileNo;
Local string &smsMessage;
&mobileNo = "0555555555";
&smsMessage = "TestSMS TestSMS";
sendTextSMS(&smsMessage, &mobileNo);
No comments:
Post a Comment