cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Microsoft Employee

Handling return object from WebApi

G'Day,

 

I'm a WPF dev and do MVVM day to day. How can this be achieved within PowerApp? I have the following object being returned from the WebApi call

 

[swagger snippit]

        "CarDetails": {
            "type""object",
            "properties": {
                "plate": {
                    "type""string"
                },
                "confidence": {
                    "type""number"
                },
                "FileURL": {
                    "type""string"
                }
            }
        }
 
At the moment I've got the WebApi connection being called in a Camera's OnSelect method as showing in https://powerapps.microsoft.com/en-us/blog/custom-api-for-image-upload/ . How do I take the returned object and have multiple controls such as text fields and bind to the return object's members?
 
Cam
1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff carlosag
PowerApps Staff

Re: Handling return object from WebApi

The way I prefer dealing with simple objects is saving them in a context variable by doing:

OnVisible  UpdateContext( {Result: MyCustomApi.GetObject()} )

 

and later you can refer to it anywhere like:

TextBox1.Text = Result.properties.plate

TextBox2.Text = Result.properties.confidence

 

 

View solution in original post

5 REPLIES 5
Meneghino
Level 10

Re: Handling return object from WebApi

G'day @caadam

I hope I have understood your question correctly.

 

In the blog post you quoted, the proposed OnSelect code is the following:

Collect(MyPictures, {URL:ImageUploadAPI.UploadImage(Camera1.Photo, {fileName: TextInput1.Text}).FileURL, Name:TextInput1.Text, Time:Now()})

This means that each time the button is pressed, a new image is uploaded to Azure and the return object is appended as a new record to the MyPictures collection.  This means that all data is present in the MyPictures collection.  You can inpect the contents of the MyPictures collection in design mode via the Content tab of PowerApps Studio.

 

You can display the contents of MyPictures to the user of the app by simply creating for example a vertical custom gallery and set its Items property to MyPictures, then place the text box controls in the template to bind then to the collection's records.

 

Again, I hope this addresses your question, but please let me know.

Microsoft Employee

Re: Handling return object from WebApi

G'Day @Meneghino

 

Thanks for the info. Just out of interest, if MyPictures is a collection of objects, what is the singular term in PowerApps speak? Say the WebApi only returns a single entity rather than a collect... what do I call that?

 

Cam

Meneghino
Level 10

Re: Handling return object from WebApi

Hi @caadam

MyPictures is a collection.  The term 'collection' is specific to PowerApps, please see here

https://powerapps.microsoft.com/en-us/tutorials/create-update-collection/

I basically think of it as a table.

The WebApi returns a record in your case, so that you can append it to the collection via the Collect function.

Hope this helps.

Microsoft Employee

Re: Handling return object from WebApi

G'Day @Meneghino,

 

In my WebApi just returns a single record and not a collection, what is the object I save it in? Is there a datatype called 'record'?

 

Cam

PowerApps Staff carlosag
PowerApps Staff

Re: Handling return object from WebApi

The way I prefer dealing with simple objects is saving them in a context variable by doing:

OnVisible  UpdateContext( {Result: MyCustomApi.GetObject()} )

 

and later you can refer to it anywhere like:

TextBox1.Text = Result.properties.plate

TextBox2.Text = Result.properties.confidence

 

 

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 92 members 5,435 guests
Please welcome our newest community members: