web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / PowerApps and Azure fu...
Power Apps
Unanswered

PowerApps and Azure function

(0) ShareShare
ReportReport
Posted on by 19

Hello,

 

1) I have created a function app in Azure to return a value and it works fine. 

    return func.HttpResponse(f'Func = {str(Func)}', status_code=200).

 

2) In PowerApps, I have created the connector and it also works fine (see attached).

 

3) However,when I use my function in my app in the "onselect" button i receive an error:

a) The function I have used is: UpdateContext({varoutput:MyFunction.Connector(TextInput1,TextInput2)})

b) The error I had is: "The data returned in the response is invalid. Response data should be a valid JSON object.

 

4) When going to Monitor Experimental in PowerApps, I see no errors and the result is shown in "response".

 

5) This is the swagger file:

 

swagger: '2.0'

info: {version: 1.0.0, title: MyFunction}

host: xxx.xxx.xxx

basePath: /

schemes: [https]

consumes: []

produces: []

paths:

  /xxx/xxx:

    post:

      description: Calls function over https

      operationId: xxxx

      parameters:

      - name: body

        in: body

        required: true

        schema:

          type: object

          properties:

            year: {type: integer, format: int32, description: year, title: year}

            month: {type: integer, format: int32, description: month, title: month}

          required: [month, year]

      responses:

        '200':

          description: Successful response

          schema: {title: The response of the api., type: string}

        default:

          description: default

          schema: {type: string}

      summary: Summary

definitions: {}

parameters: {}

responses: {}

securityDefinitions:

  API Key: {type: apiKey, in: header, name: Key}

security:

- API Key: []

tags: []

 

Thank you,

BR

 

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    on at

    @TinaBR I believe the issue is in the content-type header. Try this instead.  

    "content-type": "application/json"

     

    This should send json data instead of plain text. 

  • TinaBR Profile Picture
    19 on at

    Hello,

     

    Thank you for your reply.

    The format of my azure function is "text/plain". This is why the content-type is by default a "text/plain' in PowerApps.

    Do you know how to change the content-type to "application/json" in PowerApps?

     

    Thank you in advance,

    Tina 

  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    Make sure that the Func is a JSON object. 

    headers={"content-type": "application/json"}
    return func.HttpResponse(f'{json.dumps(Func)}', status_code=200, headers=headers)

    You read more about it HttpResponse here

     

    If this doesn't work try this:

    return func.HttpResponse(f'{json.dumps(Func)}', status_code=200, mimetype='application/json')

     

    Note: Whenever you pass JSON data over htpp use json.dumps() instead of str(). You can read more about why this is the case here 

     

    @TinaBR Hope this helps!

     

  • TinaBR Profile Picture
    19 on at

    Hello,

     

    Thank you very much for your suggestion.

    Yes, I have tried what you have suggested and the "Func" now is a JSON object.

    In powerapps it shows: "Content-Type": "application/json" (see attached).

    The app does not show any error. But, it still does not show the result (see attached).
    In the app, in OnSelect Button I am using: MyFunction.MyConnector(TextInput1.Text,TextInput2.Text).
    The Text input 1  is supposed to be the year
    The textinput 2 is supposed to be the month
    The Label is supposed to return a number, and it is showing nothing at the moment. 
     
     
    Thank you,
    Tina
  • Community Power Platform Member Profile Picture
    on at
    Can I have the screenshot of the Azure function, please? I think I would need more information to further help
  • TinaBR Profile Picture
    19 on at

    Hello,

     

    The app is now working. The issue was not in the azure function, but in the custom connector.

    Thank you for your support!

     

    Best regards,

    Tina

  • Community Power Platform Member Profile Picture
    on at
    You're welcome, Tina. Don't forget to accept an answer as a solution if it helped. You can also add your own answer and accept that as a solution. 🙂
  • Verified answer
    TinaBR Profile Picture
    19 on at

    The solution was to pass a JSON data over http, and to create a custom connector from blank.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard