Reply

How to delete the objects returned by the previous request item

vegachow
Not applicable
Posts: 0
661     0

We have about 100 A records with a certain IP address, I use the following request to delete them with a single API call

 

POST https://localhost/wapi/v2.7.3/request

[
{ "method": "GET", "object": "record:a", "data":{"ipv4addr":"9.0.0.4", "view":"internal"}, "assign_state": {"ref": "_ref"}},
{ "method": "DELETE", "object": "##STATE:ref:##", "enable_substitution": true}
]

 

but get such an error:

 assign_state is supported only when the result operation returns a single result."

 

I don't want to use a loop to delete them one by one,  that's low effecient.

Any solutions?

 

 

 

Highlighted

Re: How to delete the objects returned by the previous request item

Adviser
Posts: 75
661     0

Hi,

 

You can CSV Export/Import to do this.

 

First export all the A records with the IP address into a CSV file as shown below:

Export the A records:
 curl -k -u admin:infoblox -H 'content-type: application/json' -X POST "https://grid-master/wapi/v2.9/fileop?_function=csv_export" -d '{"_object": "record:a","ipv4addr":"172.26.1.2"}'

Sample output:
{
    "token": "eJytUMtuwyAQvPMj6SU2i+NXb67cSJWqREoq9biyAadINlDAUfL3hUrttZceQMvODrMznBt7Rycv\nJF7caB/cyoNxxAJ54EpPZpzNLTNaphPuVnrSD2HAk5yIZYQjjquag9KIRCgeiC3Ig7A7ct7Im1Xu\njkEtckNsSfZQ7mhDG1YXWVlURQnEnzermyNaxfmPEKx/zHOgGbRVxijLGOSpi0LF7QJOapaoTO7k\nJyqx7Y/vh9dj12+Bspa2UJdFWeyAQt4lM074jPtr/L1OQkrEqok6f7HjWJsIIvqMNdDIyX0MZbjI\nPCz2X1YC+JFAqbkRSl9Sl0Wtp5dDKovfgcWIlCCkUPvurcPT8z69S+LDyUKVAoc6gpOSs/AYDHKz\n2MF9sxpySO7HwaLSdg14lc4roxPWRmzMvgCQX55o\n",
    "url": "https://grid-master/http_direct_file_io/req_id-DOWNLOAD-1029091753534101/Arecords.csv"
}

Download the CSV file:
curl -k -u admin:infoblox -H 'content-type: application/force-download' "https://grid-master/http_direct_file_io/req_id-DOWNLOAD-1029091753534101/Arecords.csv" -o "ARecordsToDelete.csv"

Sample CSV file:
header-arecord,address*,_new_address,fqdn*,_new_fqdn,comment,create_ptr,creator,ddns_principal,ddns_protected,disabled,ttl,view
arecord,172.26.1.2,,a1.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a2.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a3.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a4.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a5.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a6.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a7.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a8.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a9.demo.com,,,False,STATIC,,False,False,,default
arecord,172.26.1.2,,a10.demo.com,,,False,STATIC,,False,False,,default

Remove the stored file using the token:
curl -k -u admin:infoblox -H 'content-type: application/json' -X POST "https://grid-master/wapi/v2.9/fileop?_function=downloadcomplete" -d '{"token" : "eJytUMtuwyAQvPMj6SU2i+NXb67cSJWqREoq9biyAadINlDAUfL3hUrttZceQMvODrMznBt7Rycv\nJF7caB/cyoNxxAJ54EpPZpzNLTNaphPuVnrSD2HAk5yIZYQjjquag9KIRCgeiC3Ig7A7ct7Im1Xu\njkEtckNsSfZQ7mhDG1YXWVlURQnEnzermyNaxfmPEKx/zHOgGbRVxijLGOSpi0LF7QJOapaoTO7k\nJyqx7Y/vh9dj12+Bspa2UJdFWeyAQt4lM074jPtr/L1OQkrEqok6f7HjWJsIIvqMNdDIyX0MZbjI\nPCz2X1YC+JFAqbkRSl9Sl0Wtp5dDKovfgcWIlCCkUPvurcPT8z69S+LDyUKVAoc6gpOSs/AYDHKz\n2MF9sxpySO7HwaLSdg14lc4roxPWRmzMvgCQX55o\n"}'

Next step is to import the CSV and initiate a delete operation, like shown below:

Initiate a CSV upload:
curl -k -u admin:infoblox -H 'content-type:application/json' -X POST "https://grid-master/wapi/v2.7/fileop?_function=uploadinit"

Sample output:
{
    "token": "eJylUE1PwzAMveePbJe1Sbp+cSsak5DQQBucrTZJh6U2CUmKtn9PMgRHLhwS2X5+fvYTwtgrOHUm\n8RNG++AWEYwjlpG1QD2aYTKXzGiVXrha5cmuDz0c1UgsJwJgWHAKqAGIRBGILcha2i05rdTFortC\nwFmtiC3JnpVb2tCmaHlGecmqoiX+tFrcFOEqEt5DsP4uzxnNWFtlnPKMszxVQWJcL8CIkwI0uVMf\ngHLz9vL03O02jPKWtqwtOWV1XbMcZ2vcd3ccXScVlDFqosjf1Nh0W0rGG2PMaGTkPhrSn1UeZvv/\nbRj7mQ9KCyNRn1OVR6H7x0MKi9+G2cgbJbm56147OD7sU14SH46WVclpVkdwRDVJD8GAMLPt3Y3V\nkEM6fOgtoLZLgE/lPBqdsDZiQ/YFsTqc3A==\n",
    "url": "https://grid-master/http_direct_file_io/req_id-UPLOAD-1029091952017771/import_file"
}

Upload the CSV:
 curl -k -u admin:infoblox -H 'content-type:multipart/form-data' "https://grid-master/http_direct_file_io/req_id-UPLOAD-1029091952017771/import_file" -F file=@ARecordsToDelete.csv

Initiate the DELETE operation:
 curl -k -u admin:infoblox -H 'content-type:application/json' -X POST "https://grid-master/wapi/v2.9/fileop?_function=csv_import" -d '{"action":"START","on_error":"CONTINUE","operation":"DELETE","token":"eJylUE1PwzAMeePbJe1Sbp+cSsak5DQQBucrTZJh6U2CUmKtn9PMgRHLhwS2X5+fvYTwtgrOHUm\n8RNG++AWEYwjlpG1QD2aYTKXzGiVXrha5cmuDz0c1UgsJwJgWHAKqAGIRBGILcha2i05rdTFortC\nwFmtiC3JnpVb2tCmaHlGecmqoiX+tFrcFOEqEt5DsP4uzxnNWFtlnPKMszxVQWJcL8CIkwI0uVMf\ngHLz9vL03O02jPKWtqwtOWV1XbMcZ2vcd3ccXScVlDFqosjf1Nh0W0rGG2PMaGTkPhrSn1UeZvv/\nbRj7mQ9KCyNRn1OVR6H7x0MKi9+G2cgbJbm56147OD7sU14SH46WVclpVkdwRDVJD8GAMLPt3Y3V\nkEM6fOgtoLZLgE/lPBqdsDZiQ/YFsTqc3A==\n"}'

Sample output:
{
    "csv_import_task": {
        "_ref": "csvimporttask/b25lLmNzdl9pbXBvcnRfdGFzayQx:1",
        "admin_name": "admin",
        "file_name": "import_file",
        "file_size": 830,
        "import_id": 1,
        "lines_failed": 0,
        "lines_processed": 0,
        "lines_warning": 0,
        "on_error": "CONTINUE",
        "operation": "DELETE",
        "separator": "COMMA",
        "start_time": 1540805046,
        "status": "PENDING",
        "update_method": "OVERRIDE"
    }
}

Hope this helps,

Krishna

Showing results for 
Search instead for 
Do you mean 

Recommended for You