1

In the latest version of Azure Functions I am unable to get a function to deserialize an object on its way in.

Versions:

Azure Functions Core Tools: 1.0.0-beta.100

Function Runtime Version: 1.0.11015.0

Visual Studio: 15.3.0 Preview 4.0

Example (Not Working):

[FunctionName("Login")]
public static async Task<HttpResponseMessage> Login([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, ILogger log, AuthenticatingUser user)
{
    return await Task.Run(() =>
    {
        return req.CreateResponse(HttpStatusCode.OK, user.Username);
    });
}

When attempting to use Postman to post to this function, I always get the following error:

Exception while executing function: Functions.Login. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'user'. Microsoft.Azure.WebJobs.Host: No value was provided for parameter 'user'.

I have tried posting with form-data, x-www-form-urlencoded and raw (with JSON selected - what i expected to work). All end up with the same error.

When I take out the user from the function, I can access the JSON being passed in via:

var content = req.Content;
string jsonContent = content.ReadAsStringAsync().Result;

In previous versions of Azure Functions (notable not built using the Visual Studio extension, involves JSON files, etc) this worked as expected.

I'm posting various versions of the following:

{
    "Username": "myUserName",
    "Password": "MyPassword123"
}

Model for the user:

public class AuthenticatingUser
{
    public string Username { get; set; }
    public string Password { get; set; }
}

1 Answer 1

4

You should mark user parameter with HttpTrigger attribute:

public static async Task<HttpResponseMessage> Login(
    HttpRequestMessage req, 
    [HttpTrigger(AuthorizationLevel.Function, "post")] AuthenticatingUser user)

req will still be populated without any attribute on it.

Make sure your request's Content-Type header is set to application/json. Given that, the function will work with your JSON in request body.

Sign up to request clarification or add additional context in comments.

1 Comment

Embarrassing mistake on my part. Worked flawlessly - thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.