# Tower API Error When Removing Host From Inventory

**URL:** <https://forum.ansible.com/t/tower-api-error-when-removing-host-from-inventory/31190>\
**Category:** AWX Project\
**Created:** [September 3, 2019, 3:26pm UTC](https://forum.ansible.com/t/tower-api-error-when-removing-host-from-inventory/31190 "2019-09-03T15:26:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cade\_Lambert](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Cade\_Lambert](https://forum.ansible.com/u/Cade_Lambert)\
**Post date:** [September 3, 2019, 3:26pm UTC](https://forum.ansible.com/t/tower-api-error-when-removing-host-from-inventory/31190/1 "2019-09-03T15:26:32Z")

</div>

Not sure if this is a bug or not but I thought I’d see if anyone else has tried this and experienced the same issue. I’m attempting to use the Tower API to add and remove hosts from a temp static inventory. Adding hosts works fine, but when I try to remove that same host, I get the following JSON output error: “"id" field must be an integer.”

`

- name: Get host ID

uri:  
url: [https://tower/api/v2/inventories/18/hosts/](https://tower/api/v2/inventories/18/hosts/)  
method: GET  
body\_format: json  
force\_basic\_auth: yes  
user: “{{ tower\_user }}”  
password: “{{ tower\_pass }}”  
validate\_certs: no  
status\_code: 200  
register: host\_list  
when: inventory\_action == ‘Remove Host’

- name: Remove server from, Tower inventory  
uri:  
url: [https://tower/api/v2/inventories/18/hosts/](https://tower/api/v2/inventories/18/hosts/)  
method: POST  
body:  
id: “{{ host\_id[0] | int }}”  
disassociate: true  
body\_format: json  
force\_basic\_auth: yes  
user: “{{ tower\_user }}”  
password: “{{ tower\_pass }}”  
validate\_certs: no  
status\_code: 204  
when: inventory\_action == ‘Remove Host’

`

Here’s the JSON output when it fails:

`

fatal: [localhost]: FAILED! =\> {  
“allow”: “GET, POST, HEAD, OPTIONS”,  
“changed”: false,  
“connection”: “close”,  
“content”: “{"msg":"\"id\" field must be an integer."}”,  
“content\_language”: “en”,  
“content\_length”: “42”,  
“content\_type”: “application/json”,  
“date”: “Tue, 03 Sep 2019 15:21:12 GMT”,  
“elapsed”: 0,  
“invocation”: {  
“module\_args”: {  
“attributes”: null,  
“backup”: null,  
“body”: {  
“disassociate”: true,  
“id”: “806”  
},  
“body\_format”: “json”,  
“client\_cert”: null,  
“client\_key”: null,  
“content”: null,  
“creates”: null,  
“delimiter”: null,  
“dest”: null,  
“directory\_mode”: null,  
“follow”: false,  
“follow\_redirects”: “safe”,  
“force”: false,  
“force\_basic\_auth”: true,  
“group”: null,  
“headers”: {  
“Content-Type”: “application/json”  
},  
“http\_agent”: “ansible-httpget”,  
“method”: “POST”,  
“mode”: null,  
“owner”: null,  
“password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“regexp”: null,  
“remote\_src”: null,  
“removes”: null,  
“return\_content”: false,  
“selevel”: null,  
“serole”: null,  
“setype”: null,  
“seuser”: null,  
“src”: null,  
“status\_code”: [  
“204”  
],  
“timeout”: 30,  
“unix\_socket”: null,  
“unsafe\_writes”: null,  
“url”: “[https://tower/api/v2/inventories/18/hosts/](https://tower/api/v2/inventories/18/hosts/)”,  
“url\_password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“url\_username”: “admin”,  
“use\_proxy”: true,  
“user”: “admin”,  
“validate\_certs”: false  
}  
},  
“json”: {  
“msg”: “"id" field must be an integer.”  
},  
“msg”: “Status code was 400 and not [204]: HTTP Error 400: Bad Request”,  
“redirected”: false,  
“server”: “nginx/1.14.1”,  
“status”: 400,  
“url”: “[https://tower/api/v2/inventories/18/hosts/](https://tower/api/v2/inventories/18/hosts/)”,  
“vary”: “Accept, Accept-Language, Cookie, Origin”,  
“x\_api\_node”: “localhost”,  
“x\_api\_time”: “0.101s”,  
“x\_api\_total\_time”: “0.123s”  
}

`

I’ve tried converting host\_id to int but that doesn’t resolve the issue. host\_name and inventory\_action are inherited from a Tower survey. Tower version 3.5, Ansible version 2.8.3

---

<div class="post-metadata">

**Author:** ![Patricio\_Albornoz](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@Patricio\_Albornoz](https://forum.ansible.com/u/Patricio_Albornoz)\
**Post date:** [September 4, 2019, 11:03pm UTC](https://forum.ansible.com/t/tower-api-error-when-removing-host-from-inventory/31190/2 "2019-09-04T23:03:07Z")

</div>

try this:

id: “{{ host\_id[0] | int \* 1 }}”
