Restful API with Expressjs/Angularjs


I’ve been using Node-Red for a while but I would like to build a web app that talks to my snap-pac-R1 controller without using Node-Red. I read the Restful Api documentation and went through all the steps till this point:

I got admin and creds configurations:

I tested manually introducing an URL and providing the username and password that was asked by the browser and got my response as expected.

Manually it works, but when I try to access the Api using Expressjs or Angularjs I’m getting “ETIMEDOUT” errors.

Server Side
On Expressjs I am using the npm request module

var express = require('express');
var router = express.Router();
const request = require('request');
router.get('/test2', (req, res) => {
  request.get('', function (error, response, body) {
  console.error('error:', error); // Print the error if one occurred
  console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
  console.log('body:', body); // Print the HTML for the Google homepage.

}).auth('Proyectos', '9861', false);

Got this function from the documentation:
which specifies how to make the get request and how to send the basic HTML credentials.

The response I am getting on the console is:

            error: { Error: connect ETIMEDOUT
            at Object._errnoException (util.js:992:11)
            at _exceptionWithHostPort (util.js:1014:20)
            at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
            code: 'ETIMEDOUT',
            errno: 'ETIMEDOUT',
            syscall: 'connect',
            address: '',
            port: 80 }
            statusCode: undefined
            body: undefined

Client Side
On angular I tried a different approach using the $http.get method.

var auth = $base64.encode('mainBrain:27246');
var headers = {"Authorization": "Basic " + auth};
			method: 'GET',
			url: '',
			headers: headers
		}).then(function(data, status){

			console.log("then function instantiated");

			} else {
				console.log("no data found");


And also I am getting the same response on the browser’s console than on server side:

I know my issue is kind of long to read, but thanks a lot for your help. Greetings from Dominican Republic.

Update: if I try to send the request through Postman this is what happens.

Welcome to the Forums!

Seems like a networking issue.
Please take a screen shot and post it to this thread of the PAC Manage status read page for the networking details on this PAC Controller.

1 Like

Thanks for helping. Is this what you asked for?.

I don’t understand this issues, cause it does work if I manually insert the URL and credentials google chrome browser

1 Like

Yep, thats exactly what I was after. Thanks for posting it.

The network settings look good.
We (I have our developer @torchard working on your post as well) are trying to figure why its working from your computer - at first we thought it was a networking issue not having the gateway set, or the subnet mask mixed up, but it all looks good… so we will consider what else might be an issue.

1 Like

I’m having a lot of trouble duplicating this on my end; I’m able to see the data come up in the browser just as you described, but when I test it through Postman everything works as expected.

Do you have your “Content-Type” header set to “application/json”?

Here’s what that looks like for me in my Postman results:


If you’re not seeing that, you could try setting that header specifically for the request:

Oh god I feel embarrassed now… All I had was a spelling issue with the URL. My controller URL is, the one I introduced in the browser was correct but the one I introduced on my expressjs app and on postman was Once I fixed that it worked in both places and I am successfully getting the response.

Thank you so much for spending time helping me out. To compensate I will upload later my web app, and maybe it could be part of the list of Pac control REST API code samples for snap pac.

Thank you Beno and Torchard.


Glad you are now up and running.
Thanks for letting us know.