HTTP Post to PeopleSoft Integration Broker using Python

By Chris Malek | Mon, Apr 1, 2013

In this post, I will lay out a simple script that will show how to use Python to post to the PeopleSoft Integration Broker HttpListeningConnector. This will be a trivial example that will hopefully help someone jump start an integration project using python. In the example laid out below:

  • We are using Python 3.3 standard libraries.
  • We are posting to an asynchronous Service operation in PeopleSoft
  • We are not actually doing anything with the data in PeopleSoft other than echo it to an email in-box
  • We are not doing too much error handling in the python script.

The PeopleTools Setup

First let’s setup the PeopleSoft side.

Step 1 - Setup a Node to represent your python program

First we need a node to represent your application. This can be done here: PeopleTools > Integration Broker > Integration Setup > Nodes

Node AttributeValue
NamePTEST
Node TypeExternal
Authentication OptionPassword
Default User IDPS (or some valid user in your system. )
Password^secret^ (Note this is NOT the password for any user. This is more like a “key” for the node)
ActiveChecked

Step 2 - Create a New PeopleSoft Message Object

Now we need a PeopleSoft message object that will represent the XML that the python program will post.

PeopleTools > Integration Broker > Integration Setup > Messages

Message AttributeValue
NameCHG_TEST
VersionV1
TypeNonrowset-based

Step 3 - Create a new Service

In this example, we create a new service. You can easily re-use another service if you wish.

PeopleTools > Integration Broker > Integration Setup > Services

Service AttributeValue
NameCHG_TEST

Step 4 - Create the Handler PeopleCode

Now we need to create some PeopleCode that will run when a new message is posted to the integration broker for this Service Operation.

  • First install the dataDumper application class in your database. You can find the dataDumper code here.
  • Create an Application Package and Class with the following Package:Class Naming: CHG_I_TESTER:TESTER
  • Paste in the following code into the Class:
import PS_PT:Integration:INotificationHandler;

import CHG_DEBUG:dataDumper;

class TESTER implements PS_PT:Integration:INotificationHandler
   method OnNotify(&_MSG As Message);
end-class;

method OnNotify
   /+ &_MSG as Message +/
   /+ Extends/implements PS_PT:Integration:INotificationHandler.OnNotify +/
   /* Variable Declaration */

   Local CHG_DEBUG:dataDumper &Z = create CHG_DEBUG:dataDumper("Z.TXT");

   Local XmlDoc &doc;
   &doc = &_MSG.GetXmlDoc();
   &Z.dumpString(&doc.GenXmlString());
   &Z.emailDumpFile("your.name@yourdomain.com");
end-method;

This is some example code that will just take whatever XML was submitted to the integration broker and email that using the DataDumper class.

You will need to change the email address in the emailDumpFile method call.

Step 5 - Setup new Service Operation

Now we need to setup the actual Service Operation. There are several steps here.

PeopleTools > Integration Broker > Integration Setup > Service Operation

Service Operation AttributeValue
NameCHG_TEST
TypeAsynchronous - One Way
VersionV1
ActiveChecked
Message VersionCHG_TEST.V1
Queue NameIB_EXAMPLES (or create a new queue )
  • Click on the “Service Operation Security” link
    • Input a permission list that you have on your user profile.
    • Additionally, assign permission lists grants to a permission list that is on your “default user id” from your node definition.

Now we need to hook the CHG_I_TESTER:TESTER application class to execute when a service operation is posted. We do this on the Handler tab of the Service Operation.

Service Operation Handler AttributeValue
Handler NameTest
Handler TypeOn Notify
ImplementationApplication Class
DescriptionTester
Package NameCHG_I_TESTER
Path:
Class IDTESTER
MethodOnNotify

Now we need to setup the routing to make this node able to send Service Operations.

Service Operation Routing AttributeValue
routing nameIN_P_TEST
sender nodePTEST
Receiver NodeHRMS (whatever your default local node is )
External AliasCHG_TESTER.V1
ActiveChecked

Now our PeopleTools system should be ready to receive messages from some HTTP client.

Python Script

  • Download the posttopsoft.py python code
  • Replace the following pieces of code for your environment
    • Change the assignment to url with your PeopleTools host.
    • Change any headers['xxx'] assignments to reflect the nodes and other attributes for your installation.

Now call the python script from the command line: python posttopsoft.py

If everything when well you should see some output like this:

status :=>  200
Success
XML was Posted to PeopleSoft
Transaction ID => 7373d6dc-97ee-11e2-98ab-897d0a2926a3

The post just means that the XML made it to the Integration Broker and an “Operation Instance” was created. No code in PeopleSoft has actually fired yet. The Subscription contract still needs to be created and executed by the application. Once the subscription contract executes, you should see an email in the in-box. Generally, this happens almost in real time but any number of factors could impact the code from not firing right away. T

The PeopleSoft integration broker is a “funny bird”. It will return HTTP status 200 (OK) for all sorts of successes and errors. You actually have to parse the response message XML to determine the actual error messages. In the python script I have given, if the response header TransactionID contains a value then we assume that the integration broker accepted the XML and it will be processed whenever. If that header is not present then we assume an error occurred and just dump out the XML. I will leave it as an exercise for the reader to fill in more detailed error handling and response parsing.

We will also note that the example python script just submits an XML document that looks like this:

<?xml version="1.0" ?>
<test>Testing the HTTPListeningConnector.</test>

The XML structure submitted really does not matter as long as the handler PeopleCode knows how to decipher it. The PeopleCode handler could parse the XML and extract data and do any sort of processing like update data via SQL or Component Interface, Schedule a process, or choose to ignore the data all together. Since this is an asynchronous service operation there is no way for the handler code to pass information back to the python script. For that we would have to invoke a synchronous operation which we documented in the Synchronous HTTP Post to PeopleSoft Integration Broker using Python article.

Additional Reading

Author Info
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.

About Chris Work with Chris
Looking for pain-free PeopleSoft web services? 😀
PeopleSoft Simple Web Services (SWS)

Introducing a small but powerful PeopleSoft bolt-on that makes web services very easy. If you have a SQL statement, you can turn that into a web service in PeopleSoft in a few minutes.

Book
Integration Broker - The Missing Manual

I am in the process of writing a book called "Integration Broker - The Missing Manual" that you can read online.