Help with downloading and installing Bundles

Since the bundle/libraries have come out, I been trying to figure out how to automatically download and install a bundle .zip file from GitHub.

But If I try to use a Post command, it seems to download but it doesn't install. @gopher.ny has stated that if downloaded, it will install on it's own.

There are no errors in log and I have no hub security enabled on this C-5, running the latest code.

Any ideas?

def installBundleHandler(bundle) {
    if(logEnable) log.debug "----------- Start Install Bundle ----------"
    if(logEnable) log.debug "In installBundleHandler (${state.version}) - ($bundle)"
    try {
        def params = [
            uri: 'http://127.0.0.1:8080',
            path: '/bundle/uploadZipFromUrl',
            headers: [
                "Accept": '/',
                "ContentType": 'text/html; charset=utf-8',
            ],
            body: [
                source: bundle
                // Example source: 'https://github.com/bptworld/Hubitat/raw/master/Bundles/Blank.zip'
            ],
            timeout: 30,
            ignoreSSLIssues: true
        ]
        if(logEnable) log.debug "In installBundleHandler - Getting data ($params)"

        httpPost(params) { resp ->
            if(logEnable) log.debug "In installBundleHandler - Receiving file: ${bundle}"
            if(logEnable) log.debug "In installBundleHandler - Hopefully installing Bundle"
        }
    } catch (e) {
        log.error(getExceptionMessageWithLine(e))
    }
}

@Bago figured this out. I think maybe your body is wrong, but I haven't tested to confirm the correct form.

body:urlZip

1 Like

@bptworld Have you tried using curl? Just as a test. Also, which version are you running?

No idea how to use curl. Running the latest Beta.

Use the curl command I sent earlier. Just substitute in your values.

Much thanks to @bago. With his persistence, I now have working code. On to the next step! lol

This works...

def installBundleHandler(bundle) {
    if(logEnable) log.debug "----------- Start Install Bundle ----------"
    if(logEnable) log.debug "In installBundleHandler (${state.version}) - ($bundle)"
    try {
        def params = [
            uri: 'http://127.0.0.1:8080/bundle/uploadZipFromUrl',
            headers: [
                "Accept": '/',
                "ContentType": 'text/html; charset=utf-8',
            ],
            body: bundle,
            timeout: 30,
            ignoreSSLIssues: true
        ]
        if(logEnable) log.debug "In installBundleHandler - Getting data ($params)"
        httpPost(params) { resp ->
            if(logEnable) log.debug "In installBundleHandler - Receiving file: ${bundle}"
            if(logEnable) log.debug "In installBundleHandler - Hopefully installing Bundle"
        }
    } catch (e) {
        log.error(getExceptionMessageWithLine(e))
    }
}
5 Likes

@gopher.ny, did something change with bundles? This doesn't seem to work anymore. :hushed: No errors, just doesn't install.

example bundle:
https://github.com/bptworld/Hubitat/raw/master/Bundles/Blank.zip

Thanks

Give me a sec and I’ll send you the change.

@bptworld
The change is in the expected json (and it changed a month or two ago). I use python to push updates for my hubs, but here is the json:

                jsonData = {
                    'url':url,
                    'installer':False,
                    'pwd':''
                }
1 Like

Thank you for the response but where does that go??

Thanks!

In the post to the url, body content

It’s just a minor change from the original json required from before.

I was assuming it was the body content, but...

1 Like

I'm sorry, I'm just not following.

Where you pass in bundle in the body, pass in the bundle using the newer format.

1 Like

This should work - may have to add an import for groovy.json.JsonOutput in your code though

def installBundleHandler(bundle) {
    def jsonData =  JsonOutput.toJson([url:"$bundle",installer:FALSE, pwd:''])
    try {
        def params = [
            uri: 'http://127.0.0.1:8080/bundle/uploadZipFromUrl',
            headers: [
                "Accept": '*/*',
                "ContentType": 'text/plain; charset=utf-8',
            ],
            body: "$jsonData",
            timeout: 30,
            ignoreSSLIssues: true
        ]
        log.debug "In installBundleHandler - Getting data ($params)"
        httpPost(params) { resp ->
             log.debug "In installBundleHandler - Receiving file: ${bundle}"
        }
   } catch (e) {
        log.error(getExceptionMessageWithLine(e))
   }
}
2 Likes

Thank you! I wasn't even close. :upside_down_face:

Edit: and it works!. Thank you both very much.

2 Likes

Possible error in Bundle Manager -
I was managing my hub - and trying to get BM to show all my Bundles. One, Follow Me, would not show as installed. The app was, but I had not yet installed any children.
Once I put a child in, BM showed/displayed the associated bundle.

For my apps, only the children send their info to BM. So no, that bundle won't show up unless you create one or more children.

1 Like

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