I am struggling to get PowerShell to form a correctly formatted json entry when creating a new Google Calendar entry.
A correctly configured json, that is accepted by GC is as follows:
'{"end": {"dateTime": "2017-06-07T15:00:00Z"},
"start": {"dateTime": "2017-06-07T10:00:00Z"}
}'
However, forming a json from a hashtable (so I can use a variable dateTime) does not form it correctly, example:
$body=@{
start="2017-06-08T10:00:00Z"
end="2017-06-08T12:00:00Z"}
$json = $body | ConvertTo-Json
$json is returned as follows:
{
"start": "2017-06-08T10:00:00Z",
"end": "2017-06-08T12:00:00Z"
}
This is not accepted by the Google Cal API, an when testing with the OAuth 2.0 Playground it returns the following error:
{
"error": {
"code": 400,
"message": "Missing end time.",
"errors": [
{
"domain": "global",
"message": "Missing end time.",
"reason": "required"
}
]
}
Any ideas on how to use PowerShell to form a correctly formatted Start and End date?
Thanks :)
Using nesting:
Outputs: