Jump to content

DisplayMessage Not Working


l2g
Go to solution Solved by Luke,

Recommended Posts

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/DisplayMessage

    It 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!

post-291960-0-78323900-1520201585_thumb.png

Edited by l2g
Link to comment
Share on other sites

chef

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 by chef
Link to comment
Share on other sites

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

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... :unsure:
 

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

chef

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 by chef
Link to comment
Share on other sites

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!  :) 

  • Like 1
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...