cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
andersosthus
Level: Power Up

Issues saving from PowerApps using Custom API

Hi,

 

I'm having issues saving data back to my custom API. Let me first quickly explain what I've got:

Swagger definition with the following endpoints:

 - Get single item: "/item/{id}"

 - Get all items: "/items"

 - Put item: "/item/{id}"

 

I've added the connection to my custom API and then added that one as a datasource.

 

In my PowerApp, I have a BrowseGallery that uses the "Get all items" as it's datasource. This works as expected.

I then have a second screen with a form where I can edit the item. That form is configured to call "Get single item" with the Id of the item selected in the BrowseGallery, and show some data in editable textboxes in the edit form. This works.

 

My issue comes when trying to save the data. To the edit form, I've added a button that has SubmitForm(MyForm) as it's OnSelect formula. Clicking this gives me an error: "The data source supplied to the function is invalid".

 

I haven't been able to figure out what's going on, and most (if not all) of documentation/examples on custom APIs only deal with loading data.

 

I have one theory about what could be the issue. Our API returns results as an array. Even when asking for only one item, it is returned as an array with one item.

Because of this, when I use the "GetSingleItem" operation in the edit form, I actually have to call "MyConnection.GetSingleItem(Id).results (results is the name of the array containing the result). Could this be the issue?

 

Can I fix this on the PowerApp side, without having to change my API (I've read about Tables, could I maybe load the data to a Table and use that)?

 

Or are I doing something fundamentaly wrong ?

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Level 10

Re: Issues saving from PowerApps using Custom API

Hi @andersosthus

 

I would have thought that in order to edit the item, you would need to use the PutItem method, so that your OnSelect should be something like:

UpdateContext({MyChanges: MyConnection.PutItem(Id).changes})

Where changes is a record/table with the field names and new values.  For example:

{Field1: TextInput1.text, Field2: Value(TextInput2.Text)}

I think the SubmitForm would only work with OOB data sources in PowerApps.

 

I hope this helps.

View solution in original post

3 REPLIES 3
Meneghino
Level 10

Re: Issues saving from PowerApps using Custom API

Hi @andersosthus

 

I would have thought that in order to edit the item, you would need to use the PutItem method, so that your OnSelect should be something like:

UpdateContext({MyChanges: MyConnection.PutItem(Id).changes})

Where changes is a record/table with the field names and new values.  For example:

{Field1: TextInput1.text, Field2: Value(TextInput2.Text)}

I think the SubmitForm would only work with OOB data sources in PowerApps.

 

I hope this helps.

View solution in original post

andersosthus
Level: Power Up

Re: Issues saving from PowerApps using Custom API

Hi,

 

Thanks for the tip. I'll give that a go. Based on what I had read, doing a manual save shouldn't be needed, because PowerApps should handle pushing changes from the "local" store to the backend. But you are probably spot on that it only works with the full data sources.

Highlighted
ghrimm
Level: Powered On

Re: Issues saving from PowerApps using Custom API

Were you able to get a custom connector api to save data to the database? If so, how did you call your api method in powerapps?

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (10,354)