The dispatcher feature allows NRGship to be controlled from external applications using HTTP protocols. Be sure to look at the Sample Code section to see how NRGship can be controlled from a simple web page!

To enable the dispatcher, go to NRGship preferences, select defaults, and then the automation tab. Under Functions, check the box to enable the dispatcher.

Note: Once enabled, you will need to quit and re-open NRGship to start accepting dispatcher requests.

The dispatcher accepts the following actions:

Show - When called with a valid ID, the given shipment will be brought up on the desktop so that it can be finalized.

Ship - When called with a valid ID, the given shipment will be brought up on the desktop and the ship process will be invoked.

Rate - When called with a valid ID, the given shipment will be brought up on the desktop and the rating process will be invoked so the shipment can be finalized.

New -This action will accept NRGship formatted XML data inside of the NRGship request. A new shipment record will be created and will be displayed for the user to finalize.

Get - This is used alongside eCommerce integration. By passing an order # value along with a Button value of 1 or 2 it will then invoke the button scripts which can be used to pull an order or a list of orders.

NRGship listens on port 54242 for POST requests. The POST body should contain XML formatted text which specifies a given action along with any additional parameters.


POST body:
<Shipment><!-- optional --></Shipment>

A dispatcher call can be easily placed inside of a web page, or invoked via simple PHP coding.

HTML/JavaScript - By creating a simple XML string and some JavaScript, NRGship can be easily invoked from any web page. Simply create <Shipment> data in the NRGship XML Schema and load the web page and the data will be passed to NRGship.

<script language='javascript' type='text/javascript'>
function sendData() {
var xhr = new XMLHttpRequest();'POST', 'http://IPNUMBER:54242/posttext.html', true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) { //4 means request finished and response is ready
// alert(xhr.responseText);
var contentType = 'application/json';
xhr.setRequestHeader('Content-Type', contentType);

for (var header in this.headers) {
xhr.setRequestHeader(header, headers[header]);

// here's our data variable that we talked about earlier
var data = '<TROI_TEXT_UTF8><NRGship><id>123</id><action>show</action><Shipment>...</Shipment><button></button></NRGship></TROI_TEXT_UTF8>';

// finally send the request as binary data
<body onLoad='sendData()'>
<input id='subbtn' type='button' value='Send' onclick='sendData()'></input>

PHP - By making a CURL request from PHP, you can easily invoke the dispatcher. In the sample below, NRGship will invoke the Ship action for ID 123.


// set url and data
$url = 'http://ipnumber:54242/posttext.html';
$data = '<TROI_TEXT_UTF8><NRGship><id>123</id><action>ship</action><button></button></NRGship></TROI_TEXT_UTF8>';

// execute request
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);