Eltonmaster 0 Posted January 6, 2019 Share Posted January 6, 2019 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 More sharing options...
Luke 36879 Posted January 6, 2019 Share Posted January 6, 2019 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 More sharing options...
Eltonmaster 0 Posted January 6, 2019 Author Share Posted January 6, 2019 (edited) 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 January 6, 2019 by Eltonmaster Link to comment Share on other sites More sharing options...
Eltonmaster 0 Posted January 6, 2019 Author Share Posted January 6, 2019 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 More sharing options...
Luke 36879 Posted January 6, 2019 Share Posted January 6, 2019 I would suggest comparing to what our js api library is doing: https://github.com/MediaBrowser/Emby.ApiClient.Javascript/blob/master/apiclient.js#L2682 Thanks. Link to comment Share on other sites More sharing options...
Eltonmaster 0 Posted January 6, 2019 Author Share Posted January 6, 2019 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 More sharing options...
Luke 36879 Posted January 6, 2019 Share Posted January 6, 2019 Thanks for the feedback. Link to comment Share on other sites More sharing options...
cielpy572 1 Posted March 8, 2023 Share Posted March 8, 2023 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 More sharing options...
cielpy572 1 Posted March 10, 2023 Share Posted March 10, 2023 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. 1 Link to comment Share on other sites More sharing options...
Cheesegeezer 3086 Posted March 21, 2023 Share Posted March 21, 2023 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now