Monday 13 February 2017

Consume REST Web Service in PeopleSoft

In this example we will see how can we consume a REST web service in PeopleSoft. Before we start we should have some basic idea on REST web service. Unlike the SOAP based web services where we have  request and responses in xml form, here the request will be in form of URI (Uniform Resource Identifier) and the response can be in xml or json etc.
In REST we have four types of operations
GET – To retrieve data
POST – Update Data
PUT – Insert Data
DELETE – Delete Data
For Example:
here the parameter countrycode will vary as per the request.
So, http://services.groupkt.com/state/get/IND/all will give the list of states present in India. Similarly, http://services.groupkt.com/state/get/USA/all will list down all the states present in USA.
Other variant of this service is
There is one more input parameter in the URI stateCode. So, this URI will give details of a state identified by stateCode of country identified by countryCode

There is one more variant also, to search for a particular state in a country.
http://services.groupkt.com/state/search/IND?text=ma will list down all the states in India having text “ma” in them.

Before we go ahead, let us understand the request and response formats. We will be using PeopleTools documents technology to build the request and response messages.
In the request, we have seen that there are three types of input parameters – countryCode, stateCode and texttoSearch
So, our request document will also have three parameters of type String.
In the response, there are four parameters – country, name, abbr, capital
So, our response document will have four parameters of type String.
Steps for Implementation
  1. Create request and response documents

Navigate to PeopleTools Documents Document Builder

Add a New Value


Now, we will add three parameters to it.



Similarly, add the other two parameters also.


Validate and save the document.

Similarly, we will now create a document for the response.


As, we can see, results are under the tag “result”, we will create a document with name result to match the response.












Now, we will create another document which will include the above created document.
In this document we will insert a collection since the results are repeating.





Validate and Save the document.

  1. Create request and response messages

Navigate to PeopleTools Integration Broker Integration Setup Messages

Add a New value


Click Add

Click Save

Similarly, add the message for response.



Click Save

  1. Create REST service

Navigate to PeopleTools Integration Broker Integration Setup Services

Add a New Value



Save the changes.

  1. Create Service Operation
Open the above created service
Click on the highlighted Add button
We have three URI’s for this service
http://services.groupkt.com/state/get/{countryCode}/all
http://services.groupkt.com/state/get/{countryCode}/{stateCode}
http://services.groupkt.com/state/search/{countryCode}?text={text to search}
So, the base URL will be http://services.groupkt.com/state
Save the changes.
Validate the URI’s
Click on Generate URL
Make sure that the url is correct.
Similarly, you can verify other two URL’s
  1. PeopleCode to invoke the REST Service Operation

We have create a simple page to invoke the operation depending on various search options.


PeopleCode



Read the response and write it into file. (In continuation to above code)














The above code is written in “Search States By” FieldChange event.

  1. Test the REST Web Service

Search by Country



Output File:



Search by Country and State



Output File:



Search by Country and Text



Output File:



43 comments:

  1. Hi! Deepak:
    Thanks for sharing example.
    I tried this example but getting the following error:
    "An object of class Compound failed to deserialize. (2,693)"
    "An error happened while trying to unpack the value of an object of the given class."

    Any idea what could be wrong? I compared the PeopleCode, looks exactly like yours. I am on PT 8.55 and HCM 9.2.


    ReplyDelete
  2. Please compare the document structure and also check if you are able to access the REST URL's from you server.

    ReplyDelete
    Replies
    1. Thanks! Deepak.
      It was server problem. Initially, it was working so I did not think it could be server problem.

      Raj

      Delete
    2. what? what server problem? can you please provide details? I'm having the exact same issue now! :(

      Delete
    3. Hi Jsk and Deepak can you help with this example??

      Delete
  3. Can you help me with consuming REST web service from FCM for sending notification

    ReplyDelete
    Replies
    1. I am using Google Firebase Notification service. They have provided a REST webservice URL with POST method . However the request JSON document contains a Complex Primitive . I am unable to select a Document template having Complex Primitives. Please help me with this scenario.

      Delete
  4. I just want to send data to another system using REST to insert/update the data that i send. How can i achieve this with Consumer service

    ReplyDelete
    Replies
    1. I think you'll need to use a POST request to achieve this. I think this is what I'm trying to do too.

      Delete
  5. Can you please post a tutorial on how to send a POST REST to an API.

    ReplyDelete
  6. Is this data mocked or does it go to a real PS instance?

    Very nice writeup btw ...

    ReplyDelete
  7. Very useful blog. Currently am working on REST API integration between PS and a third party. PS needs to consume the REST with a datetime field (syncdate) as input parameter. Here is the code snippet:

    &reqMsg = CreateMessage(Operation.TEST);

    &docTmpl = &reqMsg.GetURIDocument();

    &comTmpl = &docTmpl.DocumentElement;

    &reqMsg.URIResourceIndex = 1;

    &comTmpl.GetPropertyByName("syncdate").value = DateTimeToLocalizedString(&runtime,"yyyy-mm-dd HH:mm:ss");

    I am getting following error :

    Caught Exception: Invalid parameter passed for method: SetValue of Document Primitive: syncdate.

    Any idea on how to set value of a date time document primitive?

    ReplyDelete
  8. Hello there, thank you very much for this tutorial. However i'm a bit lost in as to how do I add HEADERS to the request. Can you please give us some hints on that?

    ReplyDelete
  9. Hello Deepak, Need some help on PeopleSoft Consuming JSON MQ message.

    We configured JMSTARGET node and were able to establish the connection between MQ series.

    But we are not able to consume the JSON message. We tried to use Non-rowset message (as Peoplesoft don't have the ability to create message out of JSON Schema, we used online tool to convert JSON to XML and then got XSD and used in non-rowset creation). And created Service operation and added Handler code. But, we are not able to consume the message as it throws "Connection manager thrown GeneralFrameworkException" error.

    Then, we tried to use Document to create the message and created the Service operation but when we try to consume message, it says "Unknown JMS message Format".

    Could you please let me know if there is any documentation to Consume a JSON message using Document/non-rowset method?

    ReplyDelete
  10. Thanks so much for this article. Helps a lot.
    I do have a question. The REST API I am consuming in PeopleSoft is https: and everytime I invoke, it gives out error "Integration Gateway was not able to contact the external system...."

    Is this because it's on https? Do I need to put the certificate of the 3rd party to PeopleSoft? Or is there other reason behind this.

    ReplyDelete
    Replies
    1. Do you configure the http proxy in your web server? I think when you acces internet by proxy, you need to configure the proxy.

      Delete
  11. A few things to check
    1. See if IB is configured correctly.
    2. The URL is accessible from the web server.
    3. Yes, if the url is having https then you may need to import the certificate to your web server.

    ReplyDelete
  12. Hi, Deepak
    I need to do REST API between PeopleSoft CRM and HP ALM (Application Lifecycle Management)? I am using Document builder in CRM outbound and I need help on setup on IB Routing setup.
    ALM site admin gave me URL, API Key Name, Client ID and Secret.
    Please help.
    Thanks,

    ReplyDelete
  13. Hi Deepak,

    I am trying to hide the object label of my child document but it doesnt seem to work. Any ideas on this?

    Thanks!

    ReplyDelete
  14. Hi Deepak,

    How do we use API Key when we request to third party in PeopleSoft?

    Thanks!

    ReplyDelete
  15. 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

    ReplyDelete
  16. Hi,

    All REST services in peoplesoft based on request PS service operations respond ? in my requirement i have to post data from PS to 3rd party URL. I am trying POST method but unsuccessful. I have a experience in REST GET and PUT in both of the above based on request from 3rd party PS will respond with some data on request. but in new requirement i have to post data without any request from 3rd party. can i achieve this in REST services ?

    ReplyDelete
  17. I have a requirement in Peoplesoft.
    Send the data from PS Tables to 3rd party through REST API. I have to create an AE program to pull the data and send it to 3rd party in Jason format. I will get a response of this batch load either Success / how many records loaded..
    How do I achieve it? There will not be any request. We are scheduling the job nightly.

    I need some details . How many documents do I need to create?
    how to create messages and service Operation.

    Thanks in Advance
    Ram

    ReplyDelete
    Replies
    1. Hi are you able to achieve this.

      Delete
    2. Either document can be created or request data in JSON format can be constructed via the app engine peoplecode.

      Delete
  18. Failed to deserialize document for message name when usig JSON RESt POST service.

    ReplyDelete
  19. A critical question from myself.... How would a 3rd party, to whom we expose this Service Operation, know which Template they will be using? Or will the SO be smart enough to look at the parameters and know which URL to invoke??

    ReplyDelete
  20. Another question - do have have sample App Package Peoplecode to show how the collection is populated?
    That will be extremely useful.
    And if you set up the Document to refer to a Record and Fields from the Record, do you need Peoplecode to populate?

    ReplyDelete
  21. Hi deepak, some images of this post are broken. I trying to following it but can see the images. Would you mind to fix then please?

    ReplyDelete
  22. Hi Deepak,

    This is an excellent article you provided. I see some of the print screens are not showing up on the post. Is it possible to get all the print screens so we can follow the example in our environment?

    thanks
    Dave

    ReplyDelete
  23. Thank you for sharing your blog, seems to be useful information can’t wait to dig deep!

    ReplyDelete
  24. I can't see the images on the page

    ReplyDelete
  25. Hi Deepak...I am trying to create a request to a 3rd party with api key as header. Not sure how to implement this. any suggestions would be highly appreciated. Thank you.

    ReplyDelete
  26. Deepak, can you review this article pictures, some do not show up..
    Thanks

    ReplyDelete
  27. Images from the post are not visible, could you load those again?

    ReplyDelete
  28. Hi Ace,
    Could you please let me know whether you are able to provide api Key as authorization as I too have a similar requirement?

    Thanks & regards,

    ReplyDelete
  29. Aswindow is the Top Organization upvc entryways makers in delhi and Supply UPVC, Top of the line Entryways and Windows to Clients All around The Noida, Delhi Gurgaon and NCR. AS Window is a trailblazer in the creation of plasticized upvc window suppliers in gurugram and entryways. UPVC is a superb option in contrast to wood and metal. AS Window offers an extensive variety of wonderful and perfect home window plans that won't just change your home yet will likewise safeguard it from the rest of the world. UPVC is an all-climate, harmless to the ecosystem, intensity and commotion safe material for entryways and windows that add solace, accommodation, and style to current homes.

    ReplyDelete
  30. I am not able to get the images on this post. Can anyone confirm?

    ReplyDelete