Provide a REST web service in PeopleSoft

This document describes a simple example on how to provide a REST web service from PeopleSoft.
We are going to provide a service that returns the ISO2 code and the name of a country. The input will be an ISO3 country code.

Content

Step 1: Define documents

Define documents for input and output messages. Go to: PeopleTools > Documents > Documents Builder

Create a new document with the following parameters, this will be the request:

Package C_COUNTRY_INFO_REST_PKG
Document Name C_COUNTRY_INFO_REQ
Version Name v1

Set the root element to request and create a primitive called country_code_iso3. This should be a string of length 3.

On the JSON tab set the JSON label also to request.

Create a second document with the following parameters, this will be the response:

Package C_COUNTRY_INFO_REST_PKG
Document Name C_COUNTRY_INFO_RESP
Version Name v1

Add two primitives here called country_code_iso2 and description. Make sure to set the proper type and length.

Step 2: Define messages

Go to: PeopleTools > Integration Broker > Integration Setup > Messages
Create two messages one for the request and one for the response. The request:

The response:

Step 3: Create service

Go to: PeopleTools > Integration Broker > Integration Setup > Services
Create a new web service named C_COUNTRY_INFO_REST. Don’t forget to check the Is Provider checkbox.

Save the service and add a new service operation named C_GET_COUNTRY_INFO:

On the general tab you have to do a couple of things:

  • Define security
  • Set request parameters
  • Set response parameters

Step 3a: Define security

Click on the Service Operation Security link and assign a permission list to the service operation. The user that calls the service must have this permission list assigned via a role to be able to execute the operation.

Step 3b: Set request parameters

In the URI scroll fill in, use the following as a template: country/{country_code_iso3}
The REST base URL is pre-populated. Your REST service will later be available on a URL which is the combination of the base URL and the template. In this example, if you want to query the Netherlands it will be:

http://*******:9084/PSIGW/RESTListeningConnector/PSFT_CORE/C_GET_COUNTRY_INFO.v1/country/NLD

As document template use the created request message.

Step 3c: Set response parameters

For the response setup use the created response  message and set content-type to application/json.

Step 4: Create a handler

On the “Handlers” tab of the service operation you have to link an application class which handles the requests and returns a response.
In Application Designer create an application package like in the example below:

As code use some place holder code so you can save the application package:

import PS_PT:Integration:IRequestHandler;

class Country implements PS_PT:Integration:IRequestHandler
   method Country();
   method OnRequest(&MSG As Message) Returns Message;
end-class;

/* constructor */
method Country
end-method;

method OnRequest
   /+ &MSG as Message +/
   /+ Returns Message +/
   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/
   /* Variable Declaration */
   
   Return Null;
end-method;

Now on the “Handlers” tab link the application package to the service operation as shown below.

Click on details and fill in the parameters as shown.

Step 4a: Write handler code

Now you can finish the handler code. See the example below.

import PS_PT:Integration:IRequestHandler;

class Country implements PS_PT:Integration:IRequestHandler
   method Country();
   method OnRequest(&MSG As Message) Returns Message;
end-class;

/* constructor */
method Country
end-method;

method OnRequest
   /+ &MSG as Message +/
   /+ Returns Message +/
   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/
   /* Variable Declaration */
   
   Local string &strISO3;
   Local Record &rcdCountryTbl;
   Local Document &docReq, &docResp;
   Local Compound &compReq, &compResp;
   Local Message &msgResp;
   
   /* Get input parameters from request */
   &docReq = &MSG.GetURIDocument();
   &compReq = &docReq.DocumentElement;
   &strISO3 = &compReq.GetPropertyByName("country_code_iso3").value;
   
   /* Message */
   If &MSG.HTTPMethod = %IntBroker_HTTP_GET Then
      /* Get ISO2 and country description */
      &rcdCountryTbl = CreateRecord(Record.COUNTRY_TBL);
      &rcdCountryTbl.COUNTRY.Value = &strISO3;
      If &rcdCountryTbl.SelectByKey() Then
         /* Create response mesage*/
         &msgResp = CreateMessage(Operation.C_GET_COUNTRY_INFO_GET, %IntBroker_Response);
         
         /* Get document and root compound */
         &docResp = &msgResp.GetDocument();
         &compResp = &docResp.DocumentElement;
         
         /* Set primitives */
         &compResp.GetPropertyByName("country_code_iso2").Value = Left(&rcdCountryTbl.COUNTRY_2CHAR.Value, 2);
         &compResp.GetPropertyByName("description").Value = Left(&rcdCountryTbl.DESCR.Value, 100);
      Else
         /* Do something to handle non existing countries.... this is not implemented in this example */
         /* Only the happy flow works */
      End-If;
   End-If;
   
   /* Return response */
   Return &msgResp;
end-method; 

Step 5: Provide the REST service

Go to: PeopleTools > Integration Broker > Web Service > Provide Web Service
Here search for the REST web service and go through the wizard to publish the service. This will provide a WADL which you can use to provide to 3rd parties so they can integrate.

Step 6: Testing

Like mentioned in step 3b you can now use the following URL to test your service:

http://******:9084/PSIGW/RESTListeningConnector/PSFT_CORE/C_GET_COUNTRY_INFO.v1/country/NLD

Just copy and paste it in your browser and you will get the result shown below:

For more thorough testing you can use a tool like SoapUI:

16 thoughts on “Provide a REST web service in PeopleSoft”

  1. Hi I have done the same setup as described in tutorial,But I am facing issue while providing web service it display the popup Invalid XML, Please help.
    Peopletool: 8.55

    Thanks in Advanced

    Reply
  2. Hi,

    Thanks for the great tutorial. I’ve been trying for long hours now and I can’t get the REST service to work. Each time I get the following response:

    500 Internal Server Error
    The server encountered an unexpected condition which prevented it from fulfilling the request.

    Do you have any idea what could it mean?

    Reply
    • Rami,
      Did you ever figure this out? We have also been trying for hours and are getting the same result as you.
      500 Internal Server Error
      The server encountered an unexpected condition which prevented it from fulfilling the request.

      Reply
    • had the same problem.
      Solved after setting de webservice security as described.
      You have to add the webservice C_COUNTRY_INFO_* into any of the permissionlist you are member of. Don’t forget to give Full Access to the webservice.

      Reply
    • Your request and response documents also support XML. In Step 1 you should go to the XML tab and fill in the appropriate fields for XML.
      In Step 3b and c you have to set the content type to application/xml.
      This way your service will use XML instead of JSON.
      Of course your handler code might be a bit different as you have to parse and construct XML instead of JSON now.

      Reply
    • If you want to return multiple records then in your response document you will have to create a collection in that case (the 2nd button from the left it’s called ‘Add Collection Child’. It’s an icon with 4 green dots and a down pointing arrow).
      Also your handler code will have to be adapted of course.

      Reply
  3. Great document Marcel. I was able to refer, learn and implement the REST based web service. This is very useful and hats off to you as it covered detail level of each step, very carefully put. Thank you!

    Reply
  4. Hi,

    We have designed an Get API where we are providing the client with a list of dates. The current format is shown below:

    “minimumEffectiveDate”: “2018-03-01”,
    “availableDates”: [
    {
    “date”: “2018-03-02”
    },
    {
    “date”: “2018-03-03”
    },
    {
    “date”: “2018-03-04”
    },
    {
    “date”: “2018-03-07”
    }

    Client requires the dates to show in the following format:

    “minimumEffectiveDate”: “2018-03-01”
    “availableDates”: [
    “2018-03-02”
    “2018-03-03”
    “2018-03-07”
    ]
    Any recommendation how this can be achieved? Thanks in advance

    Reply
  5. Hi, can you please elaborate little bit not the web service provide part? I’m totally on the Country_info_rest part.

    Reply

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.