0

I am trying to set a query paramter in azure function v2. the Name query parameter remains null. What am I missing. The url I use in postman is http://localhost:7071/api/ScheduledJob/Frank

 [FunctionName("ScheduledJob")]
    public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get",
 Route = "{name}")] HttpRequest req,
                ILogger log)
    {
    string name = req.Query["name"];
    }

1 Answer 1

1

Your route definition is incorrect. Base URL defaults to /api not /api/FunctionName.

Use this -

Route = "ScheduledJob/{name}"

Now your URL becomes

http://localhost:7071/api/ScheduledJob/{name}

instead of

http://localhost:7071/api/{name}

which is what you have right now.

You also don't need to declare name as a new variable in your code, use it in the binding instead:

[FunctionName("HttpTrigger")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post",
            Route = "ScheduledJob/{name}")] HttpRequest req,
            string name,
            ILogger log)
        {

            return new OkObjectResult($"Hello, {name}");
        }
$ curl http://localhost:7071/api/ScheduledJob/Frank
Hello, Frank
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.