Add logic to the function app

William Bao 0 Reputation points
2024-11-04T18:03:45.7666667+00:00

I am following the Exercise - Add logic to the function app using the provided run.ps1 code and the input body (array). When I clicked on Run, the output gave 400 Bad Request and "Please send an array of readings in the request body". I wonder if the provided body wasn't in a proper array format or the provided run.ps1 code has issues?

Azure Azure Training
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2024-11-04T22:58:10.59+00:00

    Hey @William Bao

    That's most likely the reason for the error. The code is looking for the request to be either https://pwshfuncapp.azurewebistes.net/api/httptrigger1?name=AzureUser] or for the request body be

    {
       "name": "AzureUser"
    }
    

    Anything outside of that and the PowerShell script can't parse the request which could lead to a 400 error.


    EDIT 2024 November 5 Updating my answer to reflect the code sample you shared below. When passing the following request

    {
        "readings": [
            ...
        ]
    }
    

    You would use $request.Body.readings. For PowerShell functions, the body is parsed into a hashtable, so the properties are case-sensitive. You were able to resolve your issue by making passing Reading as the JSON payload object.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.