Let me provide a bit of context, the expected behaviour of the app and a description of my problem.
In my app, the users can click on buttons “Add to cart” when they navigate a “Products” list, or from a “Products details” page. WIth my current setup, this creates a new record in an Airtable table called “Order Items” with a status called “In cart”, and a quantity of 1. It also notes the name of the product (which is unique) and the email of the user (which is unique). The issue is that if they click a second time on “Add to cart”, a new record is created, again with a quantity of 1, instead of simply updating the quantity to 2, and so on and so forth.
What I am trying to accomplish is that when the user clicks on “Add to cart” from anywhere in the app, the following logic would apply:
IF the “Order Items” table DOES NOT contain a record with the User’s email and that specific product
THEN create a record with a quantity of 1
ELSEIF the “Order Items” table ALREADY CONTAINS a record with the User’s email and that specific product
THEN UPDATE that record (note: there would never be more than 1 record) by adding 1 to the quantity attribute
So I broke down my problem in 2:
- first off, make sure no new record is created if the cart already includes that product for that user. I achieved that by creating an Adalo collection that records which products are already in which user’s cart, and that works fine (i.e., if the cart already includes the specific product, then no new record is created.
- Find a way to update the record in the Airtable table by adding 1 to the quantity. I think I have to do this using a custom action, and this is where I need help.
Here is what I am trying which isn’t working for now:
First I create a custom action of the “Update” type
Then I input the URL, specify the fields “Email”, “Products” and “Quantity”, and use a filterByFormula to filter for only those records where the email matches
I also filterByFormula for the records where the products match
Theoretically, by filtering on email and product, I would get either 0 or 1 record, never more than 1. If I get one, I would like the quantity to be increased by 1. If I get 0, then another “Create” action would apply.
However, before I even get to the JSON body, I test the action and get the following error.
That said, what I had planned for the JSON body, was the following, which also doesn’t seem to be valid.
For reference, the API documentation looks like this, I just don’t know how to adapt it to my needs…
Thanks in advance for the help!