$Body in API route with parameters

Trying to understand this… we have a route that uses params in the URL like this:

/myroute/:param1/:param2

We then have a param block that checks those two parameters. We then have a json payload that we are sending in as the body.

If we use the param block, it errors, if no param block it works. SO my question, to confirm, you can only use $Body if you do not use the param block?

The body json will have undertermined key / value pairs based on PS that is feeding data into the route, so we can’t set parameters in the route param block.

Is there a way to use both $Body and params? Or any suggestions on how anyone else handles something like this?

You can use both at the same time.
Only thing, you must not declare $Body in the param block.
The param block is solely for URL variables or query string parameters.

Just for elaboration:
URL variables
/api/:param1/some/path/:param2/whatever
query string parameters
/api/some/path/whatever?param1=value1&param2=value2

in your endpoint you can the use everything at the same time:

Invoke-RestMethod "http://server.com/api/some/path/:param1?param2=value2" -Method POST -Body '{"Some" : "Json"}'
Param(
    $param1,
    $param2
)

"Param1: $param1"
"Param2: $param2"
"Body: $Body"

Thank you! I will have to run some more tests, but I must be hitting a bug. Body will only work if I remove the param block. Something feels off, I’ll test some more on Monday