Azure / Azure/azure-functions-host
req.body is undefined - Node Http Trigger
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 36
Description
#### Investigative information
Please provide the following:
- Timestamp: 2018-04-11
- Function App version (1.0 or 2.0-beta): 2.0.1.0 (beta) and 1.0
- Invocation ID: 330dc26c-e7b7-4b4c-81d0-d521d1ae338f
- Region: West Europe
#### Repro steps
* Create an event grid subscription which call the function url
* Read and return `req.body.data.validationCode` in the function
#### Expected behavior
Defined `req.body` with the actual value from the HTTP POST request
#### Actual behavior
Body property of the request object is `undefined` when I try to handle a `SubscriptionValidation` request after creating a new Event grid webhook subscription from one of my storage accounts.
This is not specific to event grid SubscriptionValidation because this problem also occurs with other POST requests which also have a JSON body payload.
This is how my `req` object looks like in the context of the function:
```
{ method: 'POST',
url: '/api/landingUnzipper',
originalUrl: '/api/landingUnzipper',
headers:
{ connection: 'close',
'transfer-encoding': 'chunked',
accept: '*/*',
expect: '100-continue',
host: 'XXX.azurewebsites.net',
'max-forwards': '10',
'x-client-ip': '52.164.122.31',
'x-client-port': '5696',
'aeg-subscription-name': 'test',
'aeg-delivery-count': '0',
'aeg-data-version': '\n\u0014aeg-metadata-version\u0012\u00010',
'aeg-event-type': 'SubscriptionValidation',
'x-waws-unencoded-url': '/api/landingUnzipper?code=XXXXX==',
'client-ip': '52.164.122.31:5696',
'is-service-tunneled': '0',
'x-arr-log-id': '9f1eff0e-0a3e-4f22-95d1-ba5bce84b9cb',
'disguised-host': 'landingprocesses2.azurewebsites.net',
'x-site-deployment-id': 'XXXX',
'was-default-hostname': 'XXXX.azurewebsites.net',
'x-original-url': '/api/landingUnzipper?code=XXXX==',
'x-forwarded-for': '52.164.122.31:5696',
'x-arr-ssl': '2048|256|C=US, S=Washington, L=Redmond, O=Microsoft Corporation, OU=Microsoft IT, CN=Microsoft IT TLS CA 4|CN=*.azurewebsites.net',
'x-forwarded-proto': 'https' },
query:
{ code: 'XXXX==' },
params: {},
body: undefined }
```
As you can read, body value is **undefined**.
#### Known workarounds
No idea
#### Related information
Provide any related information
* Programming language used : Node JS 6.5.0
* Bindings used : HTTP Trigger
* Deployed in the App Service mode with Linux
#### Example source
```
module.exports = function (context, req) {
context.res = { status: 200,
body: {validationResponse: req.body[0].data.validationCode},
headers: {'Content-Type': 'application/json'}}
context.done(null, context.res)
```
```TypeError: Cannot read property '0' of undefined```
Contributor guide
Assessment
This issue has not been assessed yet.