cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TinaBR
Frequent Visitor

PowerApps and Azure function

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

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
ZabiBabar
Continued Contributor
Continued Contributor

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!

 

View solution in original post

TinaBR
Frequent Visitor

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

View solution in original post

8 REPLIES 8
ZabiBabar
Continued Contributor
Continued Contributor

@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
Frequent Visitor

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 

ZabiBabar
Continued Contributor
Continued Contributor

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!

 

View solution in original post

TinaBR
Frequent Visitor

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
ZabiBabar
Continued Contributor
Continued Contributor

Can I have the screenshot of the Azure function, please? I think I would need more information to further help
TinaBR
Frequent Visitor

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

ZabiBabar
Continued Contributor
Continued Contributor

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. 🙂
TinaBR
Frequent Visitor

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

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (47,039)