Azure function not reading JSON input

I had the most silliest of mistakes today. There’s this Flow (Power Automate) I am developing and I need to check group membership for that. Thing is, it needs a Group Id rather than name so I made this Azure Function that will check Graph API for me and get the Id of a group name I pass as input. Easy peasy, it worked fine during testing too in the portal.

When I try it in real life via PowerShell Invoke-RestMethod it doesn’t work! It doesn’t read the input I pass in as a JSON body. This stumped me for a while. I could see the input coming through to the script, but it wasn’t parsing it as JSON for some reason. On the other hand the same input when passed in via the portal as a test works fine.

Googling on this brought me to this older blog post where I saw that once upon a time Azure Functions used to do a ConvertFrom-JSON of the input. It doesn’t do that any more but that’s when I had the light blub moment 💡 that of course I’d have to pass a ContentType header! So I added a -ContentType "application/json" to Invoke-RestMethod and bingo it started working fine! Good catch because I’ll have to do the same as Headers in the HTTP connector in Flow too.

Hopefully I never forget this again! Silly mistake.