Jump to content

POST System Condiguration resets the Settings


Eltonmaster

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

Link to comment
Share on other sites

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

Link to comment
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
Link to comment
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);
  });  
});

Link to comment
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);
    });
});

Link to comment
Share on other sites

  • 4 years later...
cielpy572

current_cfg=$(curl -v http://192.168.33.120:8096/emby/System/Configuration\?api_key\=8bfdd5)

echo $current_cfg

curl -v -X POST http://192.168.33.120:8096/emby/System/Configuration\?api_key\=8bfd\
        --data "$current_cfg"

 

Same problem with curl

 

curl 7.79.1 (x86_64-apple-darwin21.0) libcurl/7.79.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.45.1
Release-Date: 2021-09-22
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets

 

Emby server version 4.7.8.0

Link to comment
Share on other sites

cielpy572
On 3/8/2023 at 6:13 PM, cielpy572 said:

current_cfg=$(curl -v http://192.168.33.120:8096/emby/System/Configuration\?api_key\=8bfdd5)

echo $current_cfg

curl -v -X POST http://192.168.33.120:8096/emby/System/Configuration\?api_key\=8bfd\
        --data "$current_cfg"

 

Same problem with curl

 

curl 7.79.1 (x86_64-apple-darwin21.0) libcurl/7.79.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.45.1
Release-Date: 2021-09-22
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets

 

Emby server version 4.7.8.0

 

Post needs some header set

 

curl -X POST "http://192.168.33.120:8096/emby/System/Configuration?api_key=" -H "accept: */*" -H "Content-Type: application/json" -d "$new_cfg"

 

This will be ok.

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
Cheesegeezer
On 06/01/2019 at 17:25, Eltonmaster said:

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);
    });
});

Check out my adminbuddy repo on GitHub. It collects all the server settings and is most JS. 
 

https://github.com/Cheesegeezer/Emby.AdminBuddy/blob/master/Configuration/AdminCopyUserConfigurationPage.js

Link to comment
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...