Reputation: 23
I'm pretty stuck and can't find anything about it on the internet. I'm also not sure how to describe the thing i'm looking for, so maybe someone can help me.
I've got some code to create a ticket in TopDesk through API using invoke-restmethod in PS.
For the request field in TopDesk, I need some output stored in a variable, but if I want to use a variable in the PS command, I need to define the JSON body with the use of @{} | covertTo-JSON
(found that somewhere on the internet).
Now this parameter I need to put through, has to have a definition. I need to give in in the value is a email or a name.
$json = @{
"callerLookup" = "{ email : [email protected] }"
} | Convertto-JSON
Now the thing is, TopDesk doesn't see the "{ email : [email protected] }"
as a correct value.
Before, I just the following (which will work, but can't use variables):
$body = '{"email": "[email protected]"}'
I hope I described my problem cleary enough and hope that someone can help me.
Thanks in advance.
Kind regards,
Damian
Upvotes: 0
Views: 286
Reputation: 25001
For ConvertTo-Json to produce the serialized { "property" : "value" }
syntax, you must pass it an object that has a property called property
and an associated value equal to value
. You can easily create this scenario with the [pscustomobject]
accelerator.
$json = @{
callerLookup = [pscustomobject]@{email = '[email protected]'}
} | ConvertTo-Json
Upvotes: 1