Can I use the PaperCut (XML-RPC) API in Node.js?

761 views Asked by At

I was going to use PaperCut API though as far as I can judge XML-RPC doesn't support Node.JS or I couldn't find an appropriate client for the purpose. Here's the link with PaperCut API: https://www.papercut.com/support/resources/manuals/ng-mf/common/topics/tools-web-services.html

I was wondering who had been able to get it working in JavaScript. I'm using Node.js in QNAP (in Container Station). If it can be run in Python should I install Python container? Could I use a snippet of code in Python requesting it from Node.js?

1

There are 1 answers

0
Alec the Geek On

I work for PaperCut Software

Sorry it took me so long to reply to this, but I eventually found a free afternoon to knock up some code.

var xmlrpc = require('xmlrpc')

const authToken = 'token'

const hostAddress = "172.24.96.1"
 
// Waits briefly to give the XML-RPC server time to start up and start
// listening
setTimeout(function () {
  // Creates an XML-RPC client. Passes the host information on where to
  // make the XML-RPC calls.
  var client = xmlrpc.createClient({ host: hostAddress, port: 9191, path: '/rpc/api/xmlrpc'})
 
  // Sends a method call to the PaperCut MF/NG server

  client.methodCall(`api.${process.argv[2]}`, [authToken].concat(process.argv.slice(3)), function (error, value) {
    // Results of the method response
    if (undefined === error || null === error) {
        console.log(`Method response for \'${process.argv[2]}\': ${value}`)
    }
    else
    {
        console.log(`Error response for \'${process.argv[2]}\': ${error}`)
    }
  })
 
}, 1000)

To run this from the command line try something like

node main.js getUserProperty alec balance