Jump to content
Eltonmaster

POST System Condiguration resets the Settings

Recommended Posts

Eltonmaster

Hey guys,
I stumbled upon your awesome piece of software about a month ago.
Since then I am working my way up to a complete automated build.

Right now I would like to understand how the POST request works.
I am trying my hardest since two days to be able to update the whitelisted IP-Addresses using nodejs.

 

When I copy the complete json using Postman everything works just fine.
But when I try to get the json from the server and just reupload it (for testing purposes) it resets my settings on the server (success code 204).

It may be a simple http error that I am unable to see.

Here is my nodejs playground so far.

const request = require('request');

var obj

request('http://localhost:8096/emby/System/Configuration?api_key=5058514e6c2443a9b03cbcbcf308f06f',  (err, res, body) => {
  if (err) { return console.log(err); }
  
  var inbetween = JSON.parse(body);
  obj = inbetween;
  
});

JSON.stringify(obj);

var options = {
  uri: 'http://localhost:8096/emby/System/Configuration?api_key=5058514e6c2443a9b03cbcbcf308f06f',
  method: 'POST',
  json : obj 
};

console.log(obj);

request(options, function (error, response, body) {
  if (!error && response.statusCode == 204) {
    console.log(body.id) // Print the shortened url.
  }
	 console.log(response.statusCode);
	
	// console.log(body);
});

If you need some server logs just say so.

Eltonmaster

Share this post


Link to post
Share on other sites
Luke

Hi, I would check the request body and make sure it contains the configuration object. Please let us know if this helps. Thanks.

Share this post


Link to post
Share on other sites
Eltonmaster

When I log the request body (without tempering with it) it contains the settings json as one long string.

Interesting as it is if I copy that logged out one long string into postman it resets the emby setting too.
But when I pretty print it the right way, the server accepts it.

 

I tried it again and when I post a copy of the whole body into postman it works.
The problem has to be related to how I post the data in nodejs

Edited by Eltonmaster

Share this post


Link to post
Share on other sites
Eltonmaster

I changed my code a bit and now I get 500 as status code.
As I wrote before, I saved the body and posted it using postman and it works just fine.
logging out the options object looks as expected (although the obj is wrapped by ' (which is probably normal but I am grabbing straws here)).
 

const request = require('request');
const fs = require('fs');

var obj

request('http://localhost:8096/emby/System/Configuration?api_key=5058514e6c2443a9b03cbcbcf308f06f',  (err, res, body) => {
  if (err) { return console.log(err); }

  // console.log(body);
  
  fs.writeFile('body.txt', body, (err) => {  
    if (err) throw err;
    console.log('file saved');
});
  obj = body;  

  var options = {
    uri: 'http://localhost:8096/emby/System/Configuration?api_key=5058514e6c2443a9b03cbcbcf308f06f',
    method: 'POST',
    json : obj 
  };

  console.log(options.json);


  request(options, function (error, response, body) {
    if (!error && response.statusCode == 204) {
      // console.log(body.id) // Print the shortened url.
    }
     console.log(response.statusCode);
    
    // console.log(body);
  });  
});

Share this post


Link to post
Share on other sites
Eltonmaster

It works now, but sadly not because I understood why, but because I swapped my http library and now it just works flawless.
Thank you for the help tho.

My now working Code:
 

const unirest = require('unirest');
const readline = require('readline-sync');


unirest.get('http://localhost:8096/emby/System/Configuration?api_key=5058514e6c2443a9b03cbcbcf308f06f',(response) => {

var importconfig = response.raw_body;
var fileedit = JSON.parse(importconfig);
  fileedit.RemoteIPFilter.push(readline.question('IP to add: '));
  console.log(fileedit);

  unirest.post('http://localhost:8096/emby/System/Configuration?api_key=5058514e6c2443a9b03cbcbcf308f06f')
    .headers({'Content-Type': 'application/json'})
    .send(JSON.stringify(fileedit))
    .end(function (response) {
      console.log(response);
    });
});

Share this post


Link to post
Share on other sites
Luke

Thanks for the feedback.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...