Sunday 10 December 2023

PeopleSoft REST GET Web Service

Representational State Transfer (REST) is a style of doing Web services that is becoming increasingly popular among web developers because of its simplicity over SOAP and other methods.

1. Build the Template Document 

Documents represent a hierarchical data structure like a Rowset object.  They have a logical and physical representation in XML, HTML and JSON . A document object that will capture all the parameters that may be sent inbound to your web service. 

In this simple example, we will only have one parameter. 







now build a message object based on the document template we built above.

PeopleTools > Integration Broker > Integration Setup > Messages


2. Build the Document & Message for Response


3. Create a REST Service 




3. Create a Service Operation



3. Create  a Service Operation Handler







import PS_PT:Integration:IRequestHandler;

Class GET_STD_DATA implements PS_PT:Integration:IRequestHandler

   method OnRequest(&msgRequest As Message) Returns Message;

   method OnError(&pRequestMsg As Message) Returns string;

  end-class;

method OnRequest

   /+ &msgRequest as Message +/

   /+ Returns Message +/

   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/

   

   Local Message &response, &request;

   Local string &parm1, &parm2, &SecurityKey, &StdID, &L_OPERPSWDSALT1, &FindHash;

   Local string &OEMPLID, &ONAME_DISPLAY, &OSEX, &OCAMPUS_ID, &OACAD_CAREER, &OACAD_PROG, &OPROG_STATUS, &OPROG_REASON, &OADMIT_TERM, &OEXP_GRAD_TERM, &OACAD_PLAN, &ODegree, &OMajor, &OACAD_YEAR, &OYRDESCR, &ODESCRSHORT, &OEFFDT;

   Local string &resultSalt = "123";

   Local string &resultSalt1 = "456";

   Local string &resultSalt2 = "789";

   Local Compound &com;

   &response = CreateMessage(@("Operation." | &msgRequest.OperationName), %IntBroker_Response);

   

   Local Document &reqDOC, &respDOC;

   

   /*---------------------- Request Message -------------------------*/

   

   &reqDOC = &msgRequest.GetURIDocument();

   &com = &reqDOC.DocumentElement;

   &SecurityKey = &com.GetPropertyByName("MYID").value;

   

   /*--------------- Response Message ------------------------------*/

   SQLExec(SQL.L_GET_ID_FROM_TRANSTEXT, &SecurityKey, &StdID);

   SQLExec("select L_OPERPSWDSALT1 from  PS_L_TRNS_PWD1 where OPERPSWDSALT =:1", HashWithSalt(&SecurityKey, &resultSalt), &L_OPERPSWDSALT1);

   SQLExec("select 'Y' FROM  PS_L_TRNS_PWD2 WHERE L_OPERPSWDSALT2 =:1", HashWithSalt(HashWithSalt(&SecurityKey, &resultSalt) | &L_OPERPSWDSALT1, &resultSalt2), &FindHash);

     

   If Not None(&StdID) And

         (&FindHash = "Y") Then

      SQLExec(SQL.L_STD_ACADEMIC_DTL_SQL, &StdID, &OEMPLID, &ONAME_DISPLAY, &OSEX, &OCAMPUS_ID, &OACAD_CAREER, &OACAD_PROG, &OPROG_STATUS, &OPROG_REASON, &OADMIT_TERM, &OEXP_GRAD_TERM, &OACAD_PLAN, &ODegree, &OMajor, &OACAD_YEAR, &OYRDESCR, &ODESCRSHORT, &OEFFDT);

    

   End-If;

   &respDOC = &response.GetDocument();

   &respDOC.GetElement("EMPLID").VALUE = &OEMPLID;

   &respDOC.GetElement("CAMPUS_ID").VALUE = &OCAMPUS_ID;

   &respDOC.GetElement("DISPLAY_NAME").VALUE = &ONAME_DISPLAY;

   &respDOC.GetElement("ACAD_PLAN").VALUE = &OACAD_PLAN;

   &respDOC.GetElement("PLAN_DESCR").VALUE = &OMajor;

   &respDOC.GetElement("ACAD_PROG").VALUE = &OACAD_PROG;

   &respDOC.GetElement("PROG_DESCR").VALUE = &ODegree;

   &respDOC.GetElement("YEAR_ADMITTED").VALUE = &OYRDESCR;

   &respDOC.GetElement("YEAR_GRADUATED").VALUE = &ODESCRSHORT;

   &respDOC.GetElement("ACAD_CAREER").VALUE = &OACAD_CAREER;

   &respDOC.GetElement("PROG_STATUS").VALUE = &OPROG_STATUS;

   &respDOC.GetElement("PROG_REASON").VALUE = &OPROG_REASON;

   &respDOC.GetElement("ADMIT_TERM").VALUE = &OADMIT_TERM;

   &respDOC.GetElement("EXP_GRAD_TERM").VALUE = &OEXP_GRAD_TERM;

   &respDOC.GetElement("SEX").VALUE = &OSEX;

      Return &response;

   end-method;

method OnError

   /+ &pRequestMsg as Message +/

   /+ Returns String +/

   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnError +/

   Return "Error Occured";

end-method;


Check it Using POSTMAN



No comments:

Post a Comment