evolmonster
evolmonster

Reputation: 302

Sending HTTP request to Logic app fails with " Property selection is not supported on values of type 'String'

So I have a fairly simple logic app that does a task for me, and I have a HTTP trigger on the task with a JSON object that it expects. I am calling that logic app trigger from C# as follows :

        var postData = new QERestartModel
        {
            AppName = appname,
            Environment = environment.ToString()                    
        };

        //Tranform it to Json object
        string jsonData = JsonConvert.SerializeObject(postData, Formatting.Indented);

        var azureRequestClient = new RestClient(new Uri("MyURI"));
        
        var request = new RestRequest(Method.POST);                
        request.AddHeader("Content-Type", "application/json");
        request.AddJsonBody(jsonData);
                        
        IRestResponse azureResponse = azureRequestClient.Execute(request);

When I run the C# code, I get an error on the logic app saying : InvalidTemplate. Unable to process template language expressions in action 'Get_App_Name' inputs at line '0' and column '0': 'The template language expression 'triggerBody()['AppName']' cannot be evaluated because property 'AppName' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.

If I inspect the jsonData object in VS, I can see it has escaped characters in it. So if I call the logic app directly from PostMan, and just give it the body o {"AppName":"AppName","Environment":"TEST"} It works fine. But calling it from VS produces that error. Any idea what I am doing wrong?

Thanks!

Upvotes: 0

Views: 926

Answers (1)

evolmonster
evolmonster

Reputation: 302

Ok I figured it out. I did this instead :

var request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content-Type", "application/json");
request.AddJsonBody(new { AppName = appname, Environment = environment.ToString() });

Upvotes: 2

Related Questions