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 ?
Solved! Go to Solution.
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.
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.
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.
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?
User | Count |
---|---|
139 | |
130 | |
76 | |
72 | |
70 |
User | Count |
---|---|
212 | |
200 | |
64 | |
63 | |
54 |