cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Srautio
Advocate I
Advocate I

Using Azure Functions in Powerapps Issue

I have been following this guide found here to create a basic custom connector that uses a basic HTTPrequest function to return a String.

 

https://powerapps.microsoft.com/de-de/blog/using-azure-functions-in-powerapps/

 

I have gotten everything working up the the very last step where I am trying to call the function inside Powerapps where I get the following error:

image.png

But testing the connector in the wizard works just fine and it returns the expected String.
image.png

 

Any pointers on what's going wrong here would be appriciated

 

1 ACCEPTED SOLUTION

Accepted Solutions
WilliamL
Frequent Visitor

Hello,

 

You can replace your line of code in your Azure Function with:

return req.CreateResponse(HttpStatusCode.OK, new { summary = "the-string-you-want-to-display" });

 

You can see an example from here.

Hope it helps,


William

View solution in original post

5 REPLIES 5
v-xida-msft
Community Support
Community Support

Hi @Srautio,

Could you plese share more details about the OpenAPI definition file that you specified for your custom connector?

which Authentication type do you use within your OpenAPI definition file?

 

The error message seems to tell that there is something wrong with the Response part of your OpenAPI definition file. The data the MyAzureFunction.RunThis() function returned is not valid.

Please check your C# code within your Azure Function, then make sure that the result the Azure function returned matches the data type that you specified within the Response part of your OpenAPI definition file.

The standard format of OpenAPI definition file as below:

https://procsi.blob.core.windows.net/docs/SentimentDemo.openapi_definition.json

 

Please also take a try to define a Authentication type within your OpenAPI definition file (for your custom connector), then check if the issue is solved.

In addition, please also check if you have defined a schemesbasePath, consumes, and produces within your OpenAPI definition file. If not, please also take a try to define schemesbasePathconsumes, and produces within your OpenAPI definition file as below:

 

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "MyAzureFunction"
  },
  "host": "azurefn.azurewebsites.net",
"basePath": "/",  /* <-- Modify Start */
"schemes": [
"https"
],
"consumes": [],
"produces": [
"application/json" ,
"text/plain; charset=utf-8"
], /* <-- Modify End */ "paths": { "/api/HttpTriggerCSharp1": { "get": { "description": "Calls my azure function over https", "operationId": "RunThis", "parameters": [ { "name": "code", "in": "query", "description": "code", "default": "h6ztu…[your code here]…i", "type": "string" }, { "name": "name", "in": "query", "required": true, "type": "string" } ], "responses": { "200": { "description": "Successful response", "schema": { "title": "The response of the api.", "type": "string" } } } } } } }

 

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I went through the Swagger file and added the fields you highlighted.

 

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "MyAzureFunction"
  },
  "host": "srautio-testing-swagger.azurewebsites.net",
  "basePath": "/",
  "schemes":[
    "https"
  ],
  "consumes": [],
  "produces": [
    "application/json",
    "text/plain; charset=utf-8"
  ],
  "paths": {
    "/api/HttpTriggerCSharp1": {
      "get": {
        "description": "Calls my azure function over https",
        "operationId": "RunThis",
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "description": "code",
            "default": "my azure function code",
            "type": "string",
            "x-ms-visibility": "internal"
          },
          {
            "name": "name",
            "in": "query",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "schema": {
              "title": "The response of the api.",
              "type": "string"
            }
          }
        }
      }
    }
  }
}

The C# code is the unedited example code you get from creating a function in the azure portal.

 

#r "Newtonsoft.Json"

using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];

    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

    return name != null
        ? (ActionResult)new OkObjectResult($"Hello, {name}")
        : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}

I have tested the function via postman and it seems to work just fine, and through the custom connector wizard it still works aswell.

 

Oh an there's no authentication other then the code passed in the http request from the "code" parameter.

And I have updated/removed readded the connection in powerapps aswell but same result

Anonymous
Not applicable

I have the same Issue here!

Just a simple Azrue Function, actually the same! But the response is invalid 😞

 

SyntaxEditor Code Snippet

{
  "swagger": "2.0",
  "info": {
    "title": "XXX",
    "description": "",
    "version": "1.0"
  },
  "host": "kkow-testfunction.azurewebsites.net",
  "basePath": "/",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [
  	"application/json"
  ],
  "paths": {
    "/api/HttpTrigger1": {
      "post": {
        "responses": {
          "default": {
            "description": "default",
            "schema": {
              "type": "string",
              "title": "text",
              "x-ms-visibility": ""
            }
          }
        },
        "summary": "Azure",
        "description": "Call",
        "operationId": "RunMe",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": false,
            "schema": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "name"
                }
              }
            }
          }
        ]
      }
    }
  },
  "definitions": {},
  "parameters": {},
  "responses": {},
  "securityDefinitions": {},
  "security": [],
  "tags": []
}

 

 

Oh its been quite a while since I first encountered this error, sadly I never got it to work but have since then moved on to creating other custom connectors and graph etc.

 

However I have come to re-think the types of apps I will build due to the licensing changes coming in February 2019.

  • Although makers do not require a specific license to create PowerApps and Flows that use custom or premium connectors, users of Apps and Flows that are based on custom or premium connectors require Plan 1 or Plan 2 licenses. 

 

WilliamL
Frequent Visitor

Hello,

 

You can replace your line of code in your Azure Function with:

return req.CreateResponse(HttpStatusCode.OK, new { summary = "the-string-you-want-to-display" });

 

You can see an example from here.

Hope it helps,


William

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,460)