# How to Add a Groups to host Using the awx API?

**URL:** <https://forum.ansible.com/t/how-to-add-a-groups-to-host-using-the-awx-api/39617>\
**Category:** Get Help\
**Tags:** awx\
**Created:** [January 15, 2025, 10:50am UTC](https://forum.ansible.com/t/how-to-add-a-groups-to-host-using-the-awx-api/39617 "2025-01-15T10:50:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![krushnarama](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@krushnarama](https://forum.ansible.com/u/krushnarama)\
**Post date:** [January 15, 2025, 10:50am UTC](https://forum.ansible.com/t/how-to-add-a-groups-to-host-using-the-awx-api/39617/1 "2025-01-15T10:50:14Z")

</div>

**How to Add a Groups to host Using the awx API?**.

I have a groups( example- group\_myproduct) that contains the common variables, I want to add the groups, group\_myproduct to a host . How can I achieve this ?

---

<div class="post-metadata">

**Author:** ![krushnarama](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@krushnarama](https://forum.ansible.com/u/krushnarama)\
**Post date:** [January 16, 2025, 7:07am UTC](https://forum.ansible.com/t/how-to-add-a-groups-to-host-using-the-awx-api/39617/2 "2025-01-16T07:07:23Z")

</div>

I resolved it, I used the API  
/api/v2/groups/{id}/hosts/

Details:  
**Step -1**  
[http://localhost/api/v2/groups/](http://localhost/api/v2/groups/)  
{  
“name”: “testGroup”,  
“description”: “”,  
“inventory”: inventory\_id,  
“variables”: "group\_var1: 9 "  
}

**Step -2**

Get the group\_id from the above API, Use the below api

[http://localhost/api/v2/groups/{group\_id}/hosts/](http://localhost/api/v2/groups/%7Bgroup_id%7D/hosts/)

{  
“name”: “host1”,  
“description”: “”,  
“enabled”: true,  
“instance\_id”: “”,  
“variables”: “locahost\_var1: 10”,  
“inventory”: inventory\_id  
}

Note that inventory\_id should be same for both API
