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))
}
}
tomw
October 3, 2021, 9:34pm
2
@Bago figured this out. I think maybe your body is wrong, but I haven't tested to confirm the correct form.
Bago
October 3, 2021, 10:04pm
4
@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.
Bago
October 3, 2021, 10:17pm
6
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. No errors, just doesn't install.
example bundle:
https://github.com/bptworld/Hubitat/raw/master/Bundles/Blank.zip
Thanks
Bago
May 4, 2022, 7:20pm
9
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!
Bago
May 4, 2022, 8:17pm
11
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
Bago:
In the post to the url, body content
It’s just a minor change from the original json required from before.
I'm sorry, I'm just not following.
Bago
May 4, 2022, 8:24pm
14
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.
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
system
Closed
June 13, 2023, 5:35pm
19
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.