cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HTTP Post Request to AppMon in PowerShell

yuting_wu
Guide

We have a use case where we want to dynamically change the system profiles in web dashboards. So I am trying to send HTTP Post Requests to Dynatrace Servers using powershell. Here are my pseudo code -


$auth = "username:password"

$bytes = [System.Text.Encoding]::ASCII.GetBytes($auth)

$base64 = [System.Convert]::ToBase64String($bytes)

$headers = @{}

$headers.Add("Authorization", "Basic $base64")

$siteurl = myurl

$body = myJsonString


Invoke-WebRequest -Headers $headers -Uri $siteurl -ContentType "application/json" -Method POST -Body $body


However, i am keep getting errors saying " Invoke-WebRequest : {"details":"Missing or wrong XSRF token in header X-XSRF-Header","httpStatus":499,"stackTrace":null}". Does anyone know if it is possible to send a HTTP Post this way to a dynatrace server? Thank you for your help in advance!


5 REPLIES 5

Which endpoint from documentation do you use? The ones for managing system profile are not post. They are put:

https://www.dynatrace.com/support/doc/appmon/appmon-reference/rest-interfaces/server-rest-interfaces...

Sebastian


I am not using any endpoint in Dynatrace Documentation. I am using a URL when the dashboard is reloading every time a system profile is picked. For example, https://servername/rest/charts?sessionid=live-App_1&timeframe=Offset_6_HOURS&resolution=CHART_RESOLU...


There is no option to use this endpoint. Each request has CSRF tocken in header which is received from server and refreshed before each request. You can't use this endpoint without it. As well you are not able to get this token by your self (in any supported way).

Regards,

Sebastian


Thank you. Do you know if there is a way to automatically change the system profile in AppMon web dashboard without users clicking on it?


You can configure default system profile for each dashboard. Than it should work for all users