Example: Consume a third party REST
service on PeopleSoft (GET/POST
methods)
Summary:
In PS side, how to create/consume a sample third party RESTful web service, and invoke the provided
REST service ,
PART I. GET method
For example, calling to a yahoo time service,
[Link]
Steps:
1. Create Document for the template and request/response message schema
1) Document for URL parameter template
2) Document for response
2. Create Message definition from document template and request/response document
1) Template message
2) Request/response message
3. Create REST service definition
4. Create REST service operation definitions
1) Create new service operation
2) Fill in the REST Resource Definition (e.g. base URL, URI template, document template…etc.)
3) Fill in request/response message
5. Example code to invoke the new REST service for GET method
Local Document &DOC, &DOC_Tmpl;
Local Compound &COM, &COM_Tmpl;
Local XmlDoc &XmlDoc, &xmldocReturn;
&MSG = CreateMessage(Operation.GETTIME_GET);
&DOC_Tmpl = &[Link]();
&COM_Tmpl = &DOC_Tmpl.DocumentElement;
&COM_Tmpl.GetPropertyByName("appid").Value = "YahooDemo";
&[Link] = 1;
&RESP = %[Link](&MSG);
rem *** show result;
MessageBox(0, "", 0, 0, "%1", &[Link]());
6. Test result in a button event
PART II. POST method
For example, calling CURRENCY_POST rest web service to update the currency data,
For more details on the CURRENCY_POST rest service, please refer to below solution
E-IB: Example for PeopleSoft REST provider service (GET/POST methods) (Doc ID 1533318.1)
Steps:
1. Create Document/Message definition (template and request/response messages)
1) Template message
2) Request/response message
NOTE: below is the exported schema for your reference
<?xml version="1.0"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="[Link]
y.v1" xmlns="[Link]
xmlns:xsd="[Link]
<xsd:element name="currency" type="currency_TypeShape"/>
<xsd:complexType name="currency_TypeShape">
<xsd:sequence>
<xsd:element minOccurs="0" name="currency_cd" type="currency_cd_TypeDef"/>
<xsd:element minOccurs="0" name="effdt" type="effdt_TypeDef"/>
<xsd:element minOccurs="0" name="eff_status" type="eff_status_TypeDef"/>
<xsd:element minOccurs="0" name="desc" type="desc_TypeDef"/>
<xsd:element minOccurs="0" name="descshort" type="descshort_TypeDef"/>
<xsd:element minOccurs="0" name="country" type="country_TypeDef"/>
<xsd:element minOccurs="0" name="cur_symbol" type="cur_symbol_TypeDef"/>
<xsd:element minOccurs="0" name="decimal_positions"
type="decimal_positions_TypeDef"/>
<xsd:element minOccurs="0" name="scale_positions" type="scale_positions_TypeDef"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="currency_cd_TypeDef">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="3"/>
<xsd:whiteSpace value="preserve"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="effdt_TypeDef">
<xsd:restriction base="xsd:date">
<xsd:pattern value="(\d{4}-\d{2}-\d{2})"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="eff_status_TypeDef">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="1"/>
<xsd:whiteSpace value="preserve"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="descr_TypeDef">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="30"/>
<xsd:whiteSpace value="preserve"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="descrshort_TypeDef">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="10"/>
<xsd:whiteSpace value="preserve"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="country_TypeDef">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="3"/>
<xsd:whiteSpace value="preserve"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="cur_symbol_TypeDef">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="4"/>
<xsd:whiteSpace value="preserve"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="decimal_positions_TypeDef">
<xsd:restriction base="xsd:integer">
<xsd:totalDigits value="2"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="scale_positions_TypeDef">
<xsd:restriction base="xsd:integer">
<xsd:totalDigits value="1"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
2. Create REST service definition
3. REST service operation definitions
1) Create new service operation
2) Fill in the REST Resource Definition (e.g. base URL, URI template, document template…etc.)
3) Fill in request/response message
4. Example code to invoke the new REST service for POST method
Local Document &DOC, &DOC_Tmpl;
Local Compound &COM, &COM_Tmpl;
Local XmlDoc &XmlDoc, &xmldocReturn;
&MSG = CreateMessage(Operation.POSTCURRENCY_POST);
&DOC_Tmpl = &[Link]();
&COM_Tmpl = &DOC_Tmpl.DocumentElement;
&COM_Tmpl.GetPropertyByName("currency_cd").Value = "CAD";
&[Link] = 1;
/* Get and populate the request message */
&DOC = &[Link]();
&COM = &[Link];
&[Link]("currency_cd").Value = "CAD";
&[Link]("effdt").Value = "1900-01-01";
&[Link]("eff_status").Value = "A";
&[Link]("descr").Value = "test Dollar";
&[Link]("descrshort").Value = "Dollar";
&[Link]("country").Value = "CAN";
&[Link]("cur_symbol").Value = "$";
&[Link]("decimal_positions").Value = 2;
&[Link]("scale_positions").Value = 0;
&RESP = %[Link](&MSG);
rem *** show result;
MessageBox(0, "", 0, 0, "%1", &[Link]());
5. Test result in a button event
6. Verify the result by calling CURRENCY_GET method