How to delete a Bundle in Groovy?

As the title says, I've been trying for hours (while watching the Red Sox win!) to code a way to delete a bundle. Using HPM's code to debug how it's done with apps/drivers, it's pretty straight forward BUT for bundles it seems to be different.

With apps/drivers the page source has this,

<button class="mdl-button mdl-js-button mdl-button--raised  mdl-button--accent pull-right" type="button" onclick="deleteApp(); return false">Delete</button>

<form action="/driver/edit/update" method="post" name="deleteform" id="deleteform">
    <input type="hidden" name="id" value="112" id="id" />
    <input type="hidden" name="_action_delete" value="Delete" class="delete btn btn-danger" />

and HPM uses that info like this...

        def params = [
			uri: "",
			path: "/driver/editor/update",
			requestContentType: "application/x-www-form-urlencoded",
			headers: [
				"Cookie": state.cookie
			body: [
				id: id,
				"_action_delete": "Delete"
			timeout: 300,
			textParser: true,
			ignoreSSLIssues: true

		httpPost(params) { resp ->
			if ( == null)
				paragraph "Success!"
			else {
				def matcherText ="\n","").replace("\r","")
				def matcher = matcherText.find(/<div class="alert-close close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;<\/span><\/div>(.+?)<\/div>/)

Which runs:

function deleteApp() {
  var resp = confirm("Are you sure?");
  if (resp == true) {

BUT, Bundles page source shows that they don't have the code needed to virtually push the Delete button! Bundles only have this line but not the rest.

<button class="btn mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="width: 8em; margin-right: 0.5em;" onclick="deleteBundle()">Delete</button>

Which sends it to deleteBundle():

function deleteBundle() {
    if (confirm('Are you sure?')) {
        $.get('/bundle/delete/' + bundleId, function(data) {
            window.location.href = '/bundle/list';

Now if you're still reading :grin:...

I can put 'http://(hub ip):8080/bundle/delete/999' in a browser and it will delete the bundle and bring me back to the Bundle list page (like it says it will in the function).

SO, is there a way to do it in Groovy!? Without dumping me out to the bundle list screen?


Want my HPM code for this?

Or just hints? :slight_smile:

Hint 1: Web Scaping. TheBearMay has a working example. Thanks @thebearmay
Hint 2: The latest platform has a new function that works even better.



Not quite sure I understand what you are asking... it seems httpGet() should work?


That did it, thanks!

To close out this thread, this is what I have. It might be right, it might be wrong... but it works! :grinning:

def uninstallBundle(id) {
    if(logEnable) log.debug "In uninstallBundle - Uninstalling Bundle - ${id}"
		def params = [
            uri: "${id}",
			headers: [ "Cookie": state.cookie ],
			timeout: 300,

		httpGet(params) { resp ->
            paragraph "Success!"
	catch (e) {
        paragraph "Failed!"
1 Like