Help with HTTP POST

That's one of the reason I like this HTTP driver more. You just put in the whole URL, and it does it. BUT, it only does GET, not POST.

Kodi now only accepts POST commands, I have been able to send GET in previous versions by using the send message command built into Hubitat but can't do this any longer...

Ah, then that driver above won't help you. Then the first one referenced is probably the one you need.

No idea on if you can put a user/pass with the IP though. Try it and see...

I'm no http request expert but I've banged my head against this problem enough times to know that POST requests usually require a bit more than just passing info through the uri. Most times it requires you to choose a content type (json, txt, html, etc) and sometimes requires content to be included in the header and/or body.

Like I said, I'm no expert, but I use the Postman application and try every combination I can think of till is succumbs to my ignorance/stubbornness. In your case I suspect that your content type is "application/json".

I did and no luck, however I don't know what I should be putting into the URL section based on what my working GET command was...

You could also try use RM to send the POST. This is what the config screen looks like.

Try putting this in the uri
http://user:pass@ip:port/jsonrpc

And everything after the equal sign in the body.

That was the first thing I tried, I see in the logs that it is trying to send something.

I'll post over on the Kodi forums as I guess I need to know what format the system is expecting...

It’s probably

username:password@ipaddress/therestofyourpath/

Maybe @josh can help since he worked on the ST version of this.

Check out a program called Postman. It will allow you to play around with the message and might help you figure out how it has to be formatted.

Looking back at my ST-Kodi code, it looks like I was using the same GUI.ShowNotification JSONRPC call:

ST-Kodi: showNotification()

def showNotification(title, message, image="info"){
	sendCommand("GUI.ShowNotification", [ "title": title, "message": message, "image": image ])
}

...and I was doing it with an HTTP POST as OP is looking to do:

ST-Kodi: sendCommand()

def sendCommand(command, parameters=null, id=null){
	state.lastCommand = command
	def content = [
    	"jsonrpc":"2.0",
        "method":"$command",
        "id": 1
    ]
    //if the parameters and id were passed in, add them to the JSON command
    if(parameters) content.put("params", parameters)
    if(id) content.put("id", id)
    
	def json = new groovy.json.JsonBuilder()
    def payload = json.call(content)
    log.trace "Sending command: ${command}"
    
    def path = "/jsonrpc"
    
    def headers = [:] 
    headers.put("HOST", getHostAddress())
    headers.put("Content-Type", "application/json")
    
    if(username){
    	def pair ="$username:$password"
        def basicAuth = pair.bytes.encodeBase64();
    	headers.put("Authorization", "Basic " + basicAuth )
    }

    def method = "POST"
    
    def result = new physicalgraph.device.HubAction(
        method: method,
        path: path,
        body: payload,
        headers: headers
	)
    
    result
}

Muchas Gracia @josh

I threw together a notification driver for this.
@philpugh Have at it!

2 Likes

This is awesome, does exactly what I wanted :slight_smile:
Do you use Kodi @stephack?

There is another ST app that I think @josh also wrote... One that reads Kodi state. I was using this in ST to track videoplaying status and change lighting when we played a movie. I have been unable to get this working fully in ST. I am able to pause / play etc from Hubitat but unable to get any info back

The state driven part of the ST-Kodi app relies on UPnP eventing. It works best with Kodi devices that are kept ON all the time so it can keep the UPnP event subscriptions in place.

It has some fall backs using the associated SmartApp for scheduling healthchecks on the UPnP subscriptions... so unless you've ported both the DTH and the SmartApp, you may experience some difficulty with the UPnP event subscriptions.

(Similarly, some Android devices are weird about UPnP eventing and block it)

Edit: And it has a manual fallback where tapping refresh will query for the current state rather than waiting for events.

Haven't used it in years but I figured I'd get some more practice building notification driver's :wink:.

I actually wanted to learn a bit more about formatting POST requests in HE. Making this driver helped. Glad to hear it's what you needed.

1 Like

I've managed to get the App and Driver installed but device discovery didn't find anything...

I manually added the info into the settings on the driver screen and have been able to send notificiations, play, pause, etc... basically all the buttons seem to do what they are intended. But I don't see any status returned. I have just noted your comment about Android though, I am using an Nvidia Shield

Yeah, there's probably a few things that would need to be tweaked from the SmartThings version of the driver to get it to work in Hubitat. By manually entering the configuration details into the driver, you get the basic control capabilities which all happen over HTTP, but UPnP events won't work properly without the SmartApp. Here's a thread that covers many porting details:

Like, @stephack, I haven't personally used Kodi in several years so I didn't port the DTH/SmartApp over... but the code is out there and anyone is welcome to port it and take stewardship!

1 Like
 http://name:password@ip:port

It's been awhile since any activity but curious to see if anyone was able to get integration with Kodi working. I'm not concerned with controlling Kodi but rather just getting status to trigger automations we can do with Plex. Unfortunately need to use an Nvidia Shield with Kodi to get the audio profiles I'm looking for. Thank You!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.