Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
331 stars 100 forks source link

Visual Studio Code Default Python V2 http trigger function does not work with Logic App #1468

Open matteogazzadi opened 3 months ago

matteogazzadi commented 3 months ago

I created new python V2 function Http Trigger using Visual Studio Code. I have not touched the auto generated code, just deployed it.

Then from Azure Logic App, i tried to add the function in my workflow but got constantly the error: "Cannot be called from a logic app. It must not have a custom route."

Doing the same for a C# one does indeed work.

I tried also chaning the @app.route(route="test_http") to @app.route(route="req") and @app.route(methods=["POST"]) but the error on Logic App is persisting and actually did not find a way to overcome this, neither any kind of documentation about this.

Here the function code:

import azure.functions as func
import logging

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

@app.route(route="test_http")
def test_http(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )`
bhagyshricompany commented 2 months ago

Thanks for reporting we are checking in to this and update .

nveenstra commented 1 month ago

I managed to get it working in a logic app by leaving the route empty:

@app.function_name(name="HttpTrigger")
@app.route(route="")

def main(req: func.HttpRequest) -> func.HttpResponse:
nakashimagif commented 3 weeks ago

I managed to get it working in a logic app by leaving the route empty:

@app.function_name(name="HttpTrigger")
@app.route(route="")

def main(req: func.HttpRequest) -> func.HttpResponse:

nveenstra, Thank you! This works for my case.