Skip to content
Kyle Dyer edited this page Mar 28, 2018 · 4 revisions

Example Javascript for calling the trace service.

To run this with node

  • Install the "request" package. c:> npm install request
  • Update the run.js file with your UP user-id and password.
  • Run it c:> node run.js

Here is the code

var tokenRequest = require('request');

tokenRequest({
    url: 'https://c02.my.uprr.com/api/oauth/token',
    method: 'POST',
    auth: {
        user: '<user-id>',
        pass: '<password>'
    },
    form: {
        'grant_type': 'client_credentials'
    }
}, function (err, res) {
    var json = JSON.parse(res.body);
    var accessToken = json.access_token;
    console.log("Access Token:", accessToken);

    var traceRequest = require('request');

    traceRequest({
        url: 'https://c02.my.uprr.com/api/service/customer/trace-equipment/1.3/?equipmentIds=PRGX010736,UP148355',
        method: 'GET',
        headers: {
            Accept: 'application/json'
        },
        auth: {
            'bearer': accessToken
        },
    }, function (err, res) {
        var traceResponse = JSON.parse(res.body);
        console.log("Trace Response:", traceResponse);
    });

});

Clone this wiki locally