skip to Main Content

I am trying to create a C# program to call my Azure Logic app that calls a SQL Server stored procedure which grabs data from a table. I have my logic app working, I trigger it from the Azure side and it returns the data I want.

enter image description here

But triggering it from the code side is causing problems. I would think it would be a GET since I am getting data so I have tried

var response = await _client.GetAsync("LogicAppURL");

My function is set up as follows so I can trigger it too

[FunctionName("RunLogicApp")]
public async Task RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", Route = "RunLogicApp")] HttpRequest req, ILogger log)
{
    // ....
}

But Azure is failing coming back and saying that it is expecting a POST to run this Logic App. So I tried a PostAsync and I can only get a response code of 200 back.

Which side do I need to fix, C# code or Logic App?

My stored procedure is just a select id, email, value from table

3

Answers


  1. Logic App HTTP Triggers require the POST verb. You will also likely need a SAS token, which you can get by clicking on the trigger in the Logic App. This is tacked on to the URL as a sig query parameter.

    https://yourlogicappuri/yourapp?sig=xxxxxxxxxxxxxxxxxx

    Login or Signup to reply.
  2. Which side do I need to fix, C# code or Logic App?

    To get data from Logic app by calling from c# code, follow below procedure:

    Design of Logic App:

    enter image description here

    body('Execute_stored_procedure_(V2)')?['resultsets']?['Table1']
    

    Then the c# code:

    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Extensions.Logging;
    namespace FunctionApp150
    {
        public class Function1
        {
            private readonly ILogger<Function1> _logger;
    
            public Function1(ILogger<Function1> logger)
            {
                _logger = logger;
            }
    
            [Function("Function1")]
            public async Task<IActionResult> RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
            {
                _logger.LogInformation("C# HTTP trigger function processed a request.");
                var rithmock = new StringContent("{}", System.Text.Encoding.UTF8, "application/json");
                using var rith_httpClient = new HttpClient();
                var rithcl = await rith_httpClient.PostAsync("https://prod-16.eastus.logic.azure.com:443/workflows/be1cd/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=aW9E6zJ6V1LbWAR5w", rithmock);
                var rith_proc_res = await rithcl.Content.ReadAsStringAsync();
                Console.WriteLine(rith_proc_res);
                return new OkObjectResult("Welcome to Azure Functions!");
            }
        }
    }
    

    Output:

    enter image description here

    Logic app(Code called Logic app and logic app returned response):

    enter image description here

    Login or Signup to reply.
  3. I hope this solution will give you with a very mimimal chnage to you existing implementation. A somple change needs to done in the Logic App to address this issue I guess.

    When you add a Http Request as default trigger using Old Logic App Designer the request verb will be POST by default but don’t know that this can be chnaged.

    You can change this to GET method by doing the following in OLD Logic App Designer

    1. Select All new Parameter in the Logic App Http Action
      enter image description here

    2. Select GET verb in the combobox and save it
      enter image description here

    Now your Logic App default method will be GET.

    When you run this logic app and go to Run-history you will see it has used GET verb
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search