cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Continued Contributor
Continued Contributor

Re: PowerApps and Azure function

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

Highlighted
Frequent Visitor

Re: PowerApps and Azure function

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

Re: PowerApps and Azure function

@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. 

Highlighted
Frequent Visitor

Re: PowerApps and Azure function

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 

Highlighted
Continued Contributor
Continued Contributor

Re: PowerApps and Azure function

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

Highlighted
Frequent Visitor

Re: PowerApps and Azure function

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

Re: PowerApps and Azure function

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

Re: PowerApps and Azure function

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

Highlighted
Continued Contributor
Continued Contributor

Re: PowerApps and Azure function

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

Re: PowerApps and Azure function

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
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (6,172)