Create Geofences with Powerhshell

DD
Daniel Dobbertin
Hagebau IT GmbH

Hey Guys, 
I try to Automating the Onboarding of my Customers. 

I want To Automate the creation of a Geofence. 

But i get the Following Error from Powershell: 

Invoke-restmethod : {
"$type": "ErrorDetails",
"ErrorCode": 0,
"Message": "Contract validation failed",
"Data": [
"geofenceAddRequest.$type: Error parsing value"
],
"HelpLink": null
}
In Zeile:2 Zeichen:7
+ Invoke-restmethod -Uri https://$MCFQDN/Mobicontrol/api/geofence ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

I hope you can help Me. 

Thank You

Greeting 

Daniel 

__________________________________________________________________________________________________

Code: 

$json=Get-Content "C:\Users\dobbertind\Documents\Exchange Online\Powershell Scripte\EMM\GeofenceVorlagenew.json"
Invoke-restmethod -Uri https://$MCFQDN/Mobicontrol/api/geofences -ContentType "application/json" -Method Post -Body $json -Headers $Header2

Thats The Conent of the File: 

{
"$type": "Geofence",
"Name": "test",
"Vertices": [
{
"$type": "LatLong",
"Latitude": 51.48232758114372,
"Longitude": 7.321427263198861
},
{
"$type": "LatLong",
"Latitude": 51.480049150806735,
"Longitude": 7.32170621293641
},
{
"$type": "LatLong",
"Latitude": 51.480690597252305,
"Longitude": 7.3271779193267905
},
{
"$type": "LatLong",
"Latitude": 51.48279528003457,
"Longitude": 7.326019205032357
},
{
"$type": "LatLong",
"Latitude": 51.48249354910483,
"Longitude": 7.321678533438556
},
{
"$type": "LatLong",
"Latitude": 51.48028194457554,
"Longitude": 7.322204246405475
},
{
"$type": "LatLong",
"Latitude": 51.48076970947561,
"Longitude": 7.327000036124103
},
{
"$type": "LatLong",
"Latitude": 51.48260045174229,
"Longitude": 7.325680389288776
},
{
"$type": "LatLong",
"Latitude": 51.48237996477796,
"Longitude": 7.322032585028522
},
{
"$type": "LatLong",
"Latitude": 51.48051580511012,
"Longitude": 7.322622671011798
},
{
"$type": "LatLong",
"Latitude": 51.48091002443958,
"Longitude": 7.3265816115177795
},
{
"$type": "LatLong",
"Latitude": 51.48245346055118,
"Longitude": 7.325530185583942
},
{
"$type": "LatLong",
"Latitude": 51.48215947674761,
"Longitude": 7.322279348257892
},
{
"$type": "LatLong",
"Latitude": 51.48060266728896,
"Longitude": 7.322807324514047
},
{
"$type": "LatLong",
"Latitude": 51.48103697570167,
"Longitude": 7.326304925069467
},
{
"$type": "LatLong",
"Latitude": 51.48234655756915,
"Longitude": 7.3253607874962245
},
{
"$type": "LatLong",
"Latitude": 51.48203921009992,
"Longitude": 7.322603476628915
},
{
"$type": "LatLong",
"Latitude": 51.48080311783952,
"Longitude": 7.323107731923715
},
{
"$type": "LatLong",
"Latitude": 51.48110379201345,
"Longitude": 7.326015246495858
},
{
"$type": "LatLong",
"Latitude": 51.48222629141484,
"Longitude": 7.324996007070199
},
{
"$type": "LatLong",
"Latitude": 51.48193230614682,
"Longitude": 7.322946799382821
},
{
"$type": "LatLong",
"Latitude": 51.48099688586761,
"Longitude": 7.323279393300668
},
{
"$type": "LatLong",
"Latitude": 51.481177289843345,
"Longitude": 7.325607550725595
},
{
"$type": "LatLong",
"Latitude": 51.48205257307644,
"Longitude": 7.324759972676889
},
{
"$type": "LatLong",
"Latitude": 51.48187217256309,
"Longitude": 7.32322574912037
},
{
"$type": "LatLong",
"Latitude": 51.481163926610364,
"Longitude": 7.323504698857919
},
{
"$type": "LatLong",
"Latitude": 51.48124410594958,
"Longitude": 7.325103295430795
},
{
"$type": "LatLong",
"Latitude": 51.481892217099805,
"Longitude": 7.324631226644174
},
{
"$type": "LatLong",
"Latitude": 51.48174522362591,
"Longitude": 7.323461783513681
},
{
"$type": "LatLong",
"Latitude": 51.48123742434335,
"Longitude": 7.32371927557911
},
{
"$type": "LatLong",
"Latitude": 51.48132428514781,
"Longitude": 7.324749243840829
},
{
"$type": "LatLong",
"Latitude": 51.48174522362591,
"Longitude": 7.324373734578744
},
{
"$type": "LatLong",
"Latitude": 51.48162495588576,
"Longitude": 7.323611987218515
},
{
"$type": "LatLong",
"Latitude": 51.4813510115159,
"Longitude": 7.323858750447885
},
{
"$type": "LatLong",
"Latitude": 51.48145028185666,
"Longitude": 7.324405921086923
},
{
"$type": "LatLong",
"Latitude": 51.48157723161486,
"Longitude": 7.323837292775766
},
{
"$type": "LatLong",
"Latitude": 51.482477624526545,
"Longitude": 7.321763646515662
},
{
"$type": "LatLong",
"Latitude": 51.48072037589533,
"Longitude": 7.326967132004554
},
{
"$type": "LatLong",
"Latitude": 51.48272483658168,
"Longitude": 7.325958621414954
},
{
"$type": "LatLong",
"Latitude": 51.48012570227965,
"Longitude": 7.321795833023841
},
{
"$type": "LatLong",
"Latitude": 51.482478472563315,
"Longitude": 7.324003249747011
},
{
"$type": "LatLong",
"Latitude": 51.481046267281435,
"Longitude": 7.326575013957322
},
{
"$type": "LatLong",
"Latitude": 51.48152734244336,
"Longitude": 7.322047445140183
},
{
"$type": "LatLong",
"Latitude": 51.48265651281907,
"Longitude": 7.32186505492717
},
{
"$type": "LatLong",
"Latitude": 51.482589698782164,
"Longitude": 7.321285697779953
},
{
"$type": "LatLong",
"Latitude": 51.48232758114372,
"Longitude": 7.321427263198861
}
]
}

6 years ago
SOTI MobiControl
ANSWERS
S
Scott
6 years ago

Why are you inserting anomalous instances of "$type" values in your data?

The spec just shows:

{
      "Name": "string",
      "Vertices": [
            {
                  "Latitude": 0,
                  "Longitude": 0
            }
      ]
}

Why are you adding "$type": "Geofence" and "$type" : "LatLong" in your file?