l2g 1 Posted March 4, 2018 Share Posted March 4, 2018 (edited) Very similar to this thread and this thread which was marked complete but never really rectified... I've unfortunately got the same problem. In short: I can authenticate without a problem (with the Emby API) I can retrieve the active Sessions but when i try to post to the browser based one I have open using:http://<emby host>/Sessions/<my emby browser session>/Command/DisplayMessageIt successfully posts (returns a 204) and triggers a modal popup box with none of the content i passed in with the post. I also even passed in TimeoutMs which is supposed to over-ride the Modal setting. Emby is actioning the DisplayMessage correctly but it isn't parsing the payload as part of the POST Now according to this wiki page it states: DisplayMessage (Arguments: Header, Text, TimeoutMs - if timeout is omitted, message should be modal) To which it also states: If arguments are required, the body of the request should be of contentType application/json and have the following structure:{ Arguments:{ "Name": "Value" } } I am definitely posting the application/json properly in the header along with all of the other required entries (X-Emby-Authorization and X-MediaBrowser-Token). I also assume this because I can query for active sessions in addition to actioning the Message itself. { "Arguments": { "Header": "Test Header", "Text": "My Test Message Body", "TimeoutMs" : 10000, } } I tried without the Arguments too since googling seems to turn up results of people polling Emby that way. But this yields the same result (a successful post, a successful event driven popup on the browser side, but no content - see attached screenshot): { "Header": "Test Header", "Text": "My Test Message Body", "TimeoutMs" : 10000, } I was just curious what I'm doing wrong here? My goal is to integrate this with Apprise which powers my NZBGet and SABNzbd plugins. I attached a screenshot of the Emby instance I'm connected too (via the browser) and what the pop-ups look like after it spawns. I tried to highlight in the Firefox inspector where i believe the text is supposed to go. I'm using a simple docker container based on emby/embyserver:latest (documented here). I'm wondering if it's just a lack of documentation or a small over-sight on me? Any help would be fantastic! Edited March 4, 2018 by l2g Link to comment Share on other sites More sharing options...
chef 3744 Posted March 5, 2018 Share Posted March 5, 2018 (edited) Remove the quotations around 'arguments' in your json String. Probably will fix it. Make the json object then stringify it. Or send the object, one if those two. Edited March 5, 2018 by chef Link to comment Share on other sites More sharing options...
Luke 36879 Posted March 5, 2018 Share Posted March 5, 2018 For DisplayMessage omit the arguments structure. I just tested and it seems to work fine. Are you sure there's an issue? Link to comment Share on other sites More sharing options...
l2g 1 Posted March 6, 2018 Author Share Posted March 6, 2018 Thank you guys for your fast responses! Remove the quotations around 'arguments' in your json String. For DisplayMessage omit the arguments structure. I just tested and it seems to work fine. Are you sure there's an issue? I appreciate the clarification about the arguments, I'll go option b (stringified) I was trying before: { "Header": "Test Header", "Text": "My Test Message Body", "TimeoutMs" : 10000, } Unfortunately I'm definitely still having the problem. I realize I'm repeating myself, but just to re-iterate: It's just not registering the payload but it is however (registering the request and) generating the popup (same screenshot previous shared is still applicable). I'm doing this in Python which is fantastic for JSON manipulation. The Python dictionary (dict()) above is simply converted to a JSON string using json.dumps().The full code can be seen here, but the jiffy of it looks like this (summarized): # Those who know Python know the requests library is magical # it handles all web requests (HEAD, POST, GET, etc) very well import requests # dumps() takes a dictionary and creates a string from it from json import dumps # our URL url = 'http:/localhost:8096/Sessions/my-session-id/Command/DisplayMessage' # Prepare Emby Object payload = { 'Header': title, 'Text': body, 'TimeoutMs': 10000, } headers = { 'User-Agent': 'Apprise', 'Content-Type': 'application/json', 'X-Emby-Authorization': "the-typical: header, information: here", 'X-MediaBrowser-Token': "my-authenticated-token-goes-here", } # Make the request r = requests.post( # no magic here, this is the URL url, # dumps stringifies our content data=dumps(payload), # The Emby Headers, but more importantly the 'application/json' entry # These headers can be seen above. headers=headers, ) Can you see maybe a missing header or a typo in the payload? I tried passing in the TimeoutMs as a string too in case the integer representation is what is breaking it without any luck. Hopefully something will seem obvious to you guys... Make the json object then stringify it.Or send the object, one if those two. Thanks for your feedback Chef, unfortunately i am already stringifying the object and removing the Arguments portion of the payload didn't help any . I'm certainly open to any more ideas you might have though! Link to comment Share on other sites More sharing options...
chef 3744 Posted March 6, 2018 Share Posted March 6, 2018 (edited) Okay, I'm looking through my message plugin.Maybe don't use an integer in TimeoutMs. Wrap that in quotes to make it a string. I know you tried that, but it should be a string.Probably doesn't matter but after the 10000 you have a coma. That might mess up the dictionary.But, I need a moment to read the python better. If Luke says no need for 'Arguments' to be written in the payload, then that is how it is. This is c# using the API libraries, but maybe you see something here that can help. This is taken from my Message Plugin: Note: I'm using a General Command of "DisplayMessage" to send out a message. It looks to be doing the same thing, so probably no help. var args = new Dictionary<string, string> {{"Header", message.Header}, {"Text", message.Text}}; if (message.Popup) { args.Add("TimeoutMs", "100000L"); } //Logger.Info(Plugin.Instance.Name + ": Attempting Message to " + session.DeviceName); // Logger.Info(Plugin.Instance.Name + ": Sending..." + session.DeviceName); await SessionController.SendGeneralCommand( new GeneralCommand { Arguments = args, ControllingUserId = UserManager.GetUserByName(message.User).Id.ToString(), Name = "DisplayMessage" }, CancellationToken.None); //Logger.Info("Message: " + e.SessionInfo.Client + " recieved message"); Edited March 6, 2018 by chef Link to comment Share on other sites More sharing options...
Solution Luke 36879 Posted March 6, 2018 Solution Share Posted March 6, 2018 Documentation needs to be improved, but i tested and verified using our javascript apiclient libs. You can write up a function based on this: https://github.com/MediaBrowser/Emby.ApiClient.Javascript/blob/master/apiclient.js#L3792 1 Link to comment Share on other sites More sharing options...
l2g 1 Posted March 7, 2018 Author Share Posted March 7, 2018 That solves it; the apiclient was gold and explained everything. In short it's just a documentation issue. With respect to my very first post; changing this:http://<emby host>/Sessions/<my emby browser session>/Command/DisplayMessage to this fixes everything: http://<emby host>/Sessions/<my emby browser session>/Message It's worth noting that passing the TimeoutMs as an integer (stringified) works in addition to passing it as a string as well. Thanks guys, You can mark this ticket solved/answered! 1 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