Search code examples
c#azure-logic-appsazure-functions-runtimedata-exchange

Is there a way to return data from the called azure function back to logic app who called it?


  1. I have office 365 trigger "when new e-mail arrives?"
  2. i initialize a variable username with value Max Sample
  3. Then called azure function FxNet21HttpTrigger1 and if determine there a username for the Logic App is this possible to chnge it there give another Variable back
  4. check the the username and do one thing if it is "Donald Duck" or another thing if not

I'm searching for a minimal way to set value in the azure function and react on the value in the logic app.

Logic App Designer Screenshot


Solution

  • This is using Version 1 Azure functions (version 2 and 3 are similar):

    using System.Net;
    using System.Net.Http;
    
    ....
    
    [FunctionName("MyFunction")]    
    public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
    {    
        return new GetHtmlResponseContent("<html><body>Hello <b>world</b></body></html>"};
    }
    
    private static HttpResponseMessage GetHtmlResponseContent(string msg, HttpStatusCode httpStatusCode)
    {
        var response = new HttpResponseMessage(httpStatusCode);
        response.Content = new StringContent(msg));
        response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
    
        return response;
    }  
    

    You might want to return a JSON payload containing your return value(s).

    How do I return JSON from an Azure Function