The doc says:
"For all kinds of functions other than HTTP triggers and webhooks, you can test your functions locally by calling an administration endpoint. Calling this endpoint with an HTTP POST request on the local server triggers the function."
However, attempting to invoke my timer-triggered function via Invoke-WebRequest -Method Post "http://localhost:7071/admin/functions/my_function_name"
results in an HTTP 415 Unsupported Media Type
response.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@IanKemp can you try passing Content-Type
- application/json
as headers and see if it works.
Invoke-WebRequest -Method Post "http://localhost:7071/admin/functions/my_function_name -Headers @{'Content-Type' = 'application/json'}
@IanKemp can you try passing
Content-Type
-application/json
as headers and see if it works.
Invoke-WebRequest -Method Post "http://localhost:7071/admin/functions/my_function_name" -Headers @{'Content-Type' = 'application/json'}
Results in error 400 (Bad Request)
and the function is not invoked. Also tried with the -ContentType "application/json"
switch, with same result.
@IanKemp can you try the same using Postman client as shown below:
POST http://localhost:{port}/admin/functions/{function_name}
Headers:
Content-Type : application/json
Body
{
"input": "<trigger_input>"
}
OR
Body
{
}
The message body is required to have the above JSON format
Here is the curl format :
curl --request POST -H "Content-Type:application/json" --data '{"input":"sample queue data"}' http://localhost:7071/admin/functions/QueueTriggerJS
@IanKemp can you try the same using Postman client as shown below:
POST http://localhost:{port}/admin/functions/{function_name} Headers: Content-Type : application/json Body { "input": "<trigger_input>" }
OR
Body { }
The message body is required to have the above JSON format
Here is the curl format :
curl --request POST -H "Content-Type:application/json" --data '{"input":"sample queue data"}' http://localhost:7071/admin/functions/QueueTriggerJS
Both fail with status 400. If I change the POST to a GET I receive a 200 status and function metadata, hence how I know that the function exists.
@IanKemp I've tried the same command that @KetanChawda-MSFT has tried and can confirm that it works. Also, I'm using func version 2.7.1158
for reference.
Also, could you share the logs that you see from the running func start
command?
Azure Functions Core Tools (2.7.1434 Commit hash: eac7c2888f315da0f2b51831b47f134330b501fd)
Function Runtime Version: 2.0.12555.0
I am not using func start
but simply Debug > Start from within VS2017. I assume the logs you're asking for are from the func.exe
console window that appears when I do that, if not please advise.
PowerShell invocation:
PS> Invoke-WebRequest http://localhost:7071/admin/functions/function_name
Result: StatusCode : 200
StatusDescription : OK
Content : {"name":"function_name","script_root_path_href":"http://localhost:7071/admin/vfs/function_name/","script_href":"http://localhost:7071/admin/vfs/bin/function_name.dll","config_href":
"h…
RawContent : HTTP/1.1 200 OK
Date: Tue, 23 Jul 2019 10:39:15 GMT
Server: Kestrel
Content-Type: application/json; charset=utf-8
Content-Length: 830
{"name":"function_name","script_root_path_href":"http://…
Headers : {[Date, System.String[]], [Server, System.String[]], [Content-Type, System.String[]],
[Content-Length, System.String[]]}
Images : {}
InputFields : {}
Links : {}
RawContentLength : 830
RelationLink : {}
func.exe output:
[23/07/2019 10:39:15] Executing HTTP request: {
[23/07/2019 10:39:15] "requestId": "8af23116-4004-44c5-9905-fd9173de6d9e",
[23/07/2019 10:39:15] "method": "GET",
[23/07/2019 10:39:15] "uri": "/admin/functions/function_name"
[23/07/2019 10:39:15] }
[23/07/2019 10:39:15] Executing HTTP request: {
[23/07/2019 10:39:15] "requestId": "8af23116-4004-44c5-9905-fd9173de6d9e",
[23/07/2019 10:39:15] "method": "GET",
[23/07/2019 10:39:15] "uri": "/admin/functions/function_name"
[23/07/2019 10:39:15] }
[23/07/2019 10:39:15] Executed HTTP request: {
[23/07/2019 10:39:15] "requestId": "8af23116-4004-44c5-9905-fd9173de6d9e",
[23/07/2019 10:39:15] "method": "GET",
[23/07/2019 10:39:15] "uri": "/admin/functions/function_name",
[23/07/2019 10:39:15] "identities": [
[23/07/2019 10:39:15] {
[23/07/2019 10:39:15] "type": "WebJobsAuthLevel",
[23/07/2019 10:39:15] "level": "Admin"
[23/07/2019 10:39:15] },
[23/07/2019 10:39:15] {
[23/07/2019 10:39:15] "type": "WebJobsAuthLevel",
[23/07/2019 10:39:15] "level": "Admin"
[23/07/2019 10:39:15] }
[23/07/2019 10:39:15] ],
[23/07/2019 10:39:15] "status": 200,
[23/07/2019 10:39:15] "duration": 768
[23/07/2019 10:39:15] }
PowerShell invocation:
PS> Invoke-WebRequest -Method Post http://localhost:7071/admin/functions/function_name
Invoke-WebRequest : Response status code does not indicate success: 415 (Unsupported Media Type).
At line:1 char:1
+ Invoke-WebRequest -Method Post http://localhost:7071/admin/functions/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Method: POST, Reque…ontent-Length: 0
}:HttpRequestMessage) [Invoke-WebRequest], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
func.exe output:
[23/07/2019 10:45:24] Executing HTTP request: {
[23/07/2019 10:45:24] "requestId": "60f0e8b9-62fa-429d-ab87-c3f9f61295c5",
[23/07/2019 10:45:24] "method": "POST",
[23/07/2019 10:45:24] "uri": "/admin/functions/function_name"
[23/07/2019 10:45:24] }
[23/07/2019 10:42:43] Executed HTTP request: {
[23/07/2019 10:42:43] "requestId": "6f8b9a0f-49c1-4ee0-b0f6-7a7ba497f528",
[23/07/2019 10:42:43] "method": "POST",
[23/07/2019 10:42:43] "uri": "/admin/functions/function_name",
[23/07/2019 10:42:43] "identities": [
[23/07/2019 10:42:43] {
[23/07/2019 10:42:43] "type": "WebJobsAuthLevel",
[23/07/2019 10:42:43] "level": "Admin"
[23/07/2019 10:42:43] },
[23/07/2019 10:42:43] {
[23/07/2019 10:42:43] "type": "WebJobsAuthLevel",
[23/07/2019 10:42:43] "level": "Admin"
[23/07/2019 10:42:43] }
[23/07/2019 10:42:43] ],
[23/07/2019 10:42:43] "status": 415,
[23/07/2019 10:42:43] "duration": 78
[23/07/2019 10:42:43] }
PowerShell invocation:
PS> Invoke-WebRequest -Method Post -ContentType 'application/json' http://localhost:7071/admin/functions/function_name
Invoke-WebRequest : Response status code does not indicate success: 400 (Bad Request).
At line:1 char:1
+ Invoke-WebRequest -Method Post -ContentType 'application/json' http:/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Method: POST, Reque…ontent-Length: 0
}:HttpRequestMessage) [Invoke-WebRequest], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
func.exe output:
[23/07/2019 10:45:38] Executing HTTP request: {
[23/07/2019 10:45:38] "requestId": "b48c757e-d61f-447a-a08b-06b92ce0063e",
[23/07/2019 10:45:38] "method": "POST",
[23/07/2019 10:45:38] "uri": "/admin/functions/function_name"
[23/07/2019 10:45:38] }
[23/07/2019 10:45:38] Executed HTTP request: {
[23/07/2019 10:45:38] "requestId": "b48c757e-d61f-447a-a08b-06b92ce0063e",
[23/07/2019 10:45:38] "method": "POST",
[23/07/2019 10:45:38] "uri": "/admin/functions/function_name",
[23/07/2019 10:45:38] "identities": [
[23/07/2019 10:45:38] {
[23/07/2019 10:45:38] "type": "WebJobsAuthLevel",
[23/07/2019 10:45:38] "level": "Admin"
[23/07/2019 10:45:38] },
[23/07/2019 10:45:38] {
[23/07/2019 10:45:38] "type": "WebJobsAuthLevel",
[23/07/2019 10:45:38] "level": "Admin"
[23/07/2019 10:45:38] }
[23/07/2019 10:45:38] ],
[23/07/2019 10:45:38] "status": 400,
[23/07/2019 10:45:38] "duration": 4
[23/07/2019 10:45:38] }
PowerShell invocation:
PS> Invoke-WebRequest -Method Post -Headers @{ 'Content-Type' = 'application/json' } http://localhost:7071/admin/functions/function_name
Invoke-WebRequest : Response status code does not indicate success: 400 (Bad Request).
At line:1 char:1
+ Invoke-WebRequest -Method Post -Headers @{ 'Content-Type' = 'applicat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Method: POST, Reque…ontent-Length: 0
}:HttpRequestMessage) [Invoke-WebRequest], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
func.exe output:
[23/07/2019 10:47:31] Executing HTTP request: {
[23/07/2019 10:47:31] "requestId": "cc142a79-4581-4397-a20b-4709e9750b48",
[23/07/2019 10:47:31] "method": "POST",
[23/07/2019 10:47:31] "uri": "/admin/functions/function_name"
[23/07/2019 10:47:31] }
[23/07/2019 10:47:31] Executed HTTP request: {
[23/07/2019 10:47:31] "requestId": "cc142a79-4581-4397-a20b-4709e9750b48",
[23/07/2019 10:47:31] "method": "POST",
[23/07/2019 10:47:31] "uri": "/admin/functions/function_name",
[23/07/2019 10:47:31] "identities": [
[23/07/2019 10:47:31] {
[23/07/2019 10:47:31] "type": "WebJobsAuthLevel",
[23/07/2019 10:47:31] "level": "Admin"
[23/07/2019 10:47:31] },
[23/07/2019 10:47:31] {
[23/07/2019 10:47:31] "type": "WebJobsAuthLevel",
[23/07/2019 10:47:31] "level": "Admin"
[23/07/2019 10:47:31] }
[23/07/2019 10:47:31] ],
[23/07/2019 10:47:31] "status": 400,
[23/07/2019 10:47:31] "duration": 7
[23/07/2019 10:47:31] }
UPDATE: Just realized you are trying with a Timer Triggered function. Even for this case, since its a common endpoint irrespective of the trigger, you would still need the defined payload format. So something like this should work
Invoke-WebRequest -Method Post `
-Headers @{ 'Content-Type' = 'application/json' } `
-Body '{"input": ""}' `
http://localhost:7071/admin/functions/TimeTrigger
For other non-HTTP triggered functions that _require_ a payload, you need to pass a body with a payload formatted as mentioned earlier
Invoke-WebRequest -Method Post `
-Headers @{ 'Content-Type' = 'application/json' } `
-Body '{"input": "just another string"}' `
http://localhost:7071/admin/functions/QTrigger
Also, if your function is expecting an object instead like this
public class Model
{
public string name;
}
public static class QTrigger
{
[FunctionName("QTrigger")]
public static void Run([QueueTrigger("myqueue-items", Connection = "")]Model myQueueItem, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem.name}");
}
}
then you would need to pass in the serialized JSON equivalent of the payload.
Invoke-WebRequest -Method Post `
-Headers @{ 'Content-Type' = 'application/json' } `
-Body '{"input": "{\"name\": \"just another string\"}"}' `
http://localhost:7071/admin/functions/QTrigger
So the following works:
Invoke-WebRequest -Method Post -ContentType 'application/json' -Body '{}' http://localhost:7071/admin/functions/function_name
The thing that was tripping me up was that you guys were telling me to specify an input, but my function takes no input because it is timer-triggered.
I think it would be worthwhile to add that case to the docs.
@IanKemp Thank you for the confirmation. I am glad to know that it worked.I have mentioned that on my comment.
We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.
Just to note: I was following this MS docs page about non-HTTP/ timer triggered functions and had the _exact same_ output, HTTP status code as well. That is highly confusing. I hope leaving this note here shows you MS guys that the setup and process might profit from some improvement. The ceiling is not yet reached here.
Just ran into a similar issue regarding this - when using non static function classes (I am using dependency injection in my functions) the admin endpoint for invoking the timer triggered functions is no longer working.
Haven't found a work around so far..
I had the same issue until I read @KetanChawda-MSFT response. As suggested, I added a JSON Body with only {}
and it started working.
Hi there,
we are trying to do about the same as outlined within this issue, but this time using an Event Hubs Triggered function. We already reported more details at https://github.com/Azure/azure-functions-python-worker/issues/764.
Maybe you can help us out here, @KetanChawda-MSFT or @PramodValavala-MSFT?
With kind regards,
Andreas.
Most helpful comment
Just to note: I was following this MS docs page about non-HTTP/ timer triggered functions and had the _exact same_ output, HTTP status code as well. That is highly confusing. I hope leaving this note here shows you MS guys that the setup and process might profit from some improvement. The ceiling is not yet reached here.