I'm working on a script to send a payload that should include users and optionally exclude some users. Even when I'm just including users and leaving the exclude section empty, I am having issues with the payload's syntax. I would really appreciate any help on how to structure this correctly. Here's what I have so far:
$payload = @{ "include" =
{ #
@{
"id" = $userid;
} #
},
"exclude" =
{ #
@{
} #
}
}
The documentation sample for the payload looks like this:
{
"include": [
{
"id": "BETRAYEDMILK"
},
{
"id": "PURPLEMONKEYMAD"
}
],
"exclude": [
{
"id": "VIEWTIFULSTRANGER"
}
]
}
I tried changing the brackets from curly to square, but I'm still running into issues. Any insights would be greatly appreciated!
2 Answers
It seems like you might have mixed up some syntax. For the empty lists, you shouldn’t use script blocks like {}. Instead, use an empty array like this: `exclude = @()` or you can declare it as an array: `exclude = [array]$excludeList`. This way, it won't be null but will be an empty array instead!
Could you share what your payload looks like after converting it to JSON? That might help in spotting the problem. What was the exact JSON structure you were aiming for?

I see. Thanks for pointing that out! The expected payload format has me baffled as I keep getting errors at certain lines, especially with 'exclude'. I’ll make sure to adjust those brackets and try again.