Hi
I am unable to access the foreman api v2 using the following code of simple
http request in node js.
var http = require("http");
var options = {
hostname: 'my.foreman.com',
port: 80,
path: '/api/puppetclasses',
method: 'GET',
headers: {
'Content-Type': 'application/json'
'foreman_api_version':'2'
},
auth: 'admin:changeme'
};
var 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);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
console.log( e.stack );
});
req.end();
From Foreman
"You may use v2 by either passing ‘version=2’ in the Accept Header or entering api/v2/ in the URL."
···
----- Original Message -----
> Hi
>
> I am unable to access the foreman api v2 using the following code of simple
> http request in node js.
>
> var http = require("http");
>
> var options = {
> hostname: 'my.foreman.com',
> port: 80,
> path: '/api/puppetclasses',
> method: 'GET',
> headers: {
> 'Content-Type': 'application/json'
> 'foreman_api_version':'2'
> },
> auth: 'admin:changeme'
> };
>
> var 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);
> });
> });
>
> req.on('error', function(e) {
> console.log('problem with request: ' + e.message);
> console.log( e.stack );
> });
>
>
> req.end();
>
> --
> You received this message because you are subscribed to the Google Groups
> "Foreman users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to foreman-users+unsubscribe@googlegroups.com.
> To post to this group, send email to foreman-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/foreman-users.
> For more options, visit https://groups.google.com/d/optout.
>