# How to create an OS Service Monitor on a specific host via the API.

**URL:** <https://community.dynatrace.com/t/how-to-create-an-os-service-monitor-on-a-specific-host-via-the-api/39669>\
**Category:** Open Q&A\
**Tags:** services-classic, dynatrace-api\
**Created:** [May 10, 2023, 3:19pm UTC](https://community.dynatrace.com/t/how-to-create-an-os-service-monitor-on-a-specific-host-via-the-api/39669 "2023-05-10T15:19:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DuaneRoelands](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@DuaneRoelands](https://community.dynatrace.com/u/DuaneRoelands)\
**Post date:** [May 10, 2023, 3:19pm UTC](https://community.dynatrace.com/t/how-to-create-an-os-service-monitor-on-a-specific-host-via-the-api/39669/1 "2023-05-10T15:19:12Z")

</div>

I want to create a monitor for a specific Windows service running on a specific VM, and I want to do it through the API.&nbsp; Reasons are reusability and scale; we implement new customers regularly and must set up this monitoring manually.&nbsp; I want to automate it.

I am able to retrieve a list of OS Service Monitor from the&nbsp;/api/v2/settings/objects endpoint, passing&nbsp;schemaIds=builtin:os-services-monitoring on the querystring and it returns the list of objects I expect.&nbsp; However, the individual entries in the list do NOT include any information as to what host the monitor runs on:

```markup
{
            "objectId": "vu9U3hXa3q0AAAABAB5idWlsdGluOm9zLXNlcnZpY2VzLW1vbml0b3JpbmcABEhPU1QAEDE3Njk2OEE2NEE3ODg3NkUAJGQ4NWU4ODE0LTJmN2MtM2UwZC1hMzYwLTMwMWMzZTY2NTQ5ZL7vVN4V2t6t",
            "value": {
                "enabled": true,
                "system": "WINDOWS",
                "name": "Production SERVICENAME",
                "monitoring": false,
                "alerting": true,
                "notInstalledAlerting": false,
                "statusConditionWindows": "$not($eq(running))",
                "alertActivationDuration": 30,
                "detectionConditionsWindows": [
                    {
                        "property": "ServiceName",
                        "condition": "$eq(SERVICENAME)"
                    }
                ],
                "metadata": []
            }
        }

```

I am able to add an OS Service Monitor with a POST to the same endpoint.&nbsp; I get a 200 response, and if I do a subsequent GET, I see the new OS Service Monitory in the list.&nbsp; But it’s not associated with a specific host/VM.

The API documentation doesn’t appear to address this:&nbsp; **How do I create an OS Service Monitor via this endpoint and specify the VM where the service to be monitored is running?**

---

<div class="post-metadata">

**Author:** ![Mohamed\_Hamdy](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@Mohamed\_Hamdy](https://community.dynatrace.com/u/Mohamed_Hamdy)\
**Post date:** [May 11, 2023, 2:42pm UTC](https://community.dynatrace.com/t/how-to-create-an-os-service-monitor-on-a-specific-host-via-the-api/39669/2 "2023-05-11T14:42:53Z")

</div>

Hi&nbsp;[@DuaneRoelands](https://community.dynatrace.com/user/42547),

you can use the scope to be retrieved in the fields and you will be able to get the host Id

/api/v2/settings/objects?schemaIds=builtin:os-services-monitoring&fields=objectId,value,scope

the default values are objectId and value

 ![Mohamed_Hamdy_0-1683889204504.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/6/56bdb391f3f75448055301706ac52c4e5838454b.png)

and to POST OS service to a specific host you can add the host id same as the following sample:

[  
{  
“schemaId”: “builtin:os-services-monitoring”,  
“scope”: “HOST-”,  
“value”: {  
“enabled”: true,  
“system”: “WINDOWS”,  
“name”: “Production SERVICENAME”,  
“monitoring”: false,  
“alerting”: true,  
“notInstalledAlerting”: false,  
“statusConditionWindows”: “$not($eq(running))”,  
“alertActivationDuration”: 30,  
“detectionConditionsWindows”: [  
{  
“property”: “ServiceName”,  
“condition”: “$eq(SERVICENAME)”  
}  
],  
“metadata”: []  
}  
}  
]
