When using Xano and AppGyver, updating records is a challenge. The problem is that Xano updates records using POST, while AppGyver uses PUT, and the two are not compatible.
This post describes a solution to the problem. The solution comes in two parts: 1) In Xano, develop a custom API that uses POST and will be used to update a given record., 2) In Appgyver, use CREATE RECORD to connect, through a Data Variable, to the Xano custom API.
Details are as follows:
In XANO:
For the purpose of this explanation, lets asume that we are working with an API group named PRODUCTS:
- Click on ADD API and select Start from scratch. The Add API endpoint popup opens.
- Enter an appropriate name, such as products/update_record/ {product_id} (you need to add a label within brackets to capture the id of the record to you want to update.)
- In the verb field, select POST
- Complete the other fields as appropriate and Save.
- Open the API. In the Inputs area, click on the + sign. Add a text field named products_id. Add any other field that you want to update.
- In the Function stack, click on the + sign. Select Database requests and then Edit record. Link to the target table (in our example, products)
- The edit record window opens. Set the appropriate values to field_name and field_value. In our case, field_name = id, field_value = product_id.
- In the products metadata you can turn off any field that you donât want updated. You do this by clicking on the âeyeâ icon next to the field name. This prevents the field to be set to blank if you donât provide an update value for it. (Mimicking a PATCH action).
- In the Response area, click the + sign. Set the return as model. Click Save.
In APPGYVER:
- Open Data and create a REST API Direct Integration Resource. 1) Name it appropriately, for example update_record, 2) In the Resource URL field, enter the Endpoint URL for the Xano custom API you built above.
- In CREATE RECORD (POST) do the following: Under URL placeholder create a variable with Label: id and Key: id, turn off is_static and is_optional. If you need to implement authentication, create another variable under HTTP Header with Label: authentication and Key: authentication. Go to the TEST tab and verify that you can indeed update a record. Switch off all other API calls to avoid confusion.
- Go to the page where you need to update records. Create a Data Variable and name it update_record (for example). On the right tab, select New data record
- Go to the component that will trigger the update action(i.e. button) and open the Logic Section. Use the Create Record flow function to connect to the data variable you created above (update_Record in the example)
You should now be able to update records using AppGyver and Xano.