# Change settings via API using powershell

**URL:** <https://community.dynatrace.com/t/change-settings-via-api-using-powershell/45499>\
**Category:** Dynatrace API\
**Tags:** settings, dynatrace-api\
**Created:** [May 8, 2024, 4:37pm UTC](https://community.dynatrace.com/t/change-settings-via-api-using-powershell/45499 "2024-05-08T16:37:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mario\_DT](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@Mario\_DT](https://community.dynatrace.com/u/Mario_DT)\
**Post date:** [May 8, 2024, 4:37pm UTC](https://community.dynatrace.com/t/change-settings-via-api-using-powershell/45499/1 "2024-05-08T16:37:42Z")

</div>

Hello Community,

I am trying to set the monitoring mode for a specific host using API with powershell. With cURL was very easy, with Powershell i am struggling. I have created the script below, but i get the following error:

Invoke-RestMethod : {“error”:{“code”:403,“message”:“Token is missing required scope. Use one of: settings.write (Write  
settings)”}}

Unfortunately, I didn’t manage to find an example with a POST using Powershell.

Kind regards,

Mario

$Token = ‘dt0c01.RM2ATDEG5773MBHGFGHDFGDFGHDGHKFDGHFDGHFDGFDGFDGHDFKDGHDHGDFGDGDGHDGHDG’

$Body = @{  
schemaId = ‘builtin:host.monitoring.mode’  
schemaVersion = ‘1.3’  
scope = ‘HOST-5F30AHGJHKGHJGHK’  
value = @{  
monitoringMode = ‘FULL\_STACK’  
}  
}

$Params = @{  
Uri = ‘https://{environmentid}.live.dynatrace.com/api/v2/settings/objects’  
Method = ‘POST’  
Body = ‘[’ + ($Body | ConvertTo-Json) + ‘]’  
Headers = @{  
“Content-Type” = ‘application/json; charset=utf-8’  
“Authorization” = ‘Api-Token’ + ’ ’ + $Token  
}

}

Invoke-RestMethod @Params

---

<div class="post-metadata">

**Author:** ![cbaldi](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@cbaldi](https://community.dynatrace.com/u/cbaldi)\
**Post date:** [May 8, 2024, 8:02pm UTC](https://community.dynatrace.com/t/change-settings-via-api-using-powershell/45499/2 "2024-05-08T20:02:58Z")

</div>

Your answer is in the error message. The token you are using needs to have the “settings.write” scope. You need to get another token with that scope.

You can also omit the ‘+’ in your Authorization header for easier reading and just do

“Authorization” = “Api-Token $Token”

---

<div class="post-metadata">

**Author:** ![Mario\_DT](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@Mario\_DT](https://community.dynatrace.com/u/Mario_DT)\
**Post date:** [May 9, 2024, 10:04am UTC](https://community.dynatrace.com/t/change-settings-via-api-using-powershell/45499/3 "2024-05-09T10:04:21Z")

</div>

Hi, Thanks for your reply and for mentioning about the API token. I used a GET example for validating the authentication part, then I forgot to amend the token when i was testing the POST scenario. Now I am able to execute the script, but I had to use my original setting, it didn’t work with just ‘Api-Token $Token’.

“Authorization” = ‘Api-Token’ + ’ ’ + $Token
