Upload config file using API

Hi community,

I have an issue with uploading the file using API to GenieACS.

I got the following error code when I running the code:

PS C:\Users\nzhang\testingCode> node .\savetxt.js
problem with request: getaddrinfo ENOTFOUND http://10.228.228.3
PS C:\Users\nzhang\testingCode>

Suspect it is a network issue:

PS C:\Users\nzhang\testingCode> Test-NetConnection 10.228.228.3 -p 80
WARNING: TCP connect to (10.228.228.3 : 80) failed

ComputerName : 10.228.228.3
RemoteAddress : 10.228.228.3
RemotePort : 80
InterfaceAlias : VirtualBox Host-Only Network #3
SourceAddress : 10.228.228.254
PingSucceeded : True
PingReplyDetails (RTT) : 0 ms
TcpTestSucceeded : False

My code is in below:

const http = require(‘http’);
const options = {
hostname: ‘http://10.228.228.3’,
port: 3000,
path: ‘/files’,
method: ‘PUT’,
headers: {
‘fileType’: ‘3 Vendor Configuration File’,
‘oui’: ‘70FC8C’,
‘productClass’: ‘MB425SAV2ad0UFPE4BuNW’,
‘version’: ‘2.0’,
}
};

const req = http.request(options, (res) => {
console.log(STATUS: ${res.statusCode});
console.log(HEADERS: ${JSON.stringify(res.headers)});
res.setEncoding(‘utf8’);
res.on(‘data’, (chunk) => {
console.log(BODY: ${chunk});
});
res.on(‘end’, () => {
console.log(‘No more data in response.’);
});
});

req.on(‘error’, (e) => {
console.error(problem with request: ${e.message});
});

// Write data to request body
req.write(template);
req.end();

Hi Community,

I got the following message when I executed the code. Could you please advise the reason I got “405 Method Not Allow”?

PS C:\Users\nzhang\testingCode> node .\savetxt.js
STATUS: 405
HEADERS: {“allow”:“GET”,“date”:“Mon, 04 Nov 2019 04:43:07 GMT”,“connection”:“close”,“transfer-encoding”:“chunked”}
BODY: 405 Method Not Allowed
No more data in response.
PS C:\Users\nzhang\testingCode>

My code is in below:

const options = {
host: ‘10.228.228.3’,
port: 7567,
path: ‘/files/newfile.cfg’,
method: ‘PUT’, // POST
headers: {
‘fileType’: ‘3 Vendor Configuration File’,
‘oui’: ‘70FC8C’,
‘productClass’: ‘MB425SAV2ad0UFPE4BuNW’,
‘version’: ‘2.0’,
}
};

const req = http.request(options, function(res) {
console.log(STATUS: ${res.statusCode});
console.log(HEADERS: ${JSON.stringify(res.headers)});
// res.setEncoding(‘utf8’);
res.on(‘data’, function (chunk) {
console.log(BODY: ${chunk});
});
res.on(‘end’, function() {
console.log(‘No more data in response.’);
});
});

req.on(‘error’, function(e) {
console.error(problem with request: ${e.message});
});

req.write(template);
req.end();

Hi Nolan,
if you’re using the default config, then you should make all API calls to the NBI (port 7557) and not to the UI (port 3000) or the FS (port 7567).

Sorted. Thanks. :grin: