I have a server action that gets data from an API call and some values are then stored in my database
So I first have the api call and then a database insert action
In this db record I need to store a value that needs a (complex) formula to calculate it’s value based on different values from the api call
So in the value field I have build this formula but now I wonder is this is the right way/place to do this calculation…
This is the formula:
{{($_POST.gasfee+(api.data.last_sale.total_price/1000000000000000000))+((($_POST.gasfee+(api.data.last_sale.total_price))/100))*((api.data.collection.primary_asset_contracts[0].dev_seller_fee_basis_points/100)+(api.data.collection.primary_asset_contracts[0].opensea_seller_fee_basis_points/100))}}
You’ve got access to all the variables in the $POST request and it’s not stretching the technology - it’s some basic maths frankly and shouldn’t take more than a few milliseconds and not stretch the server resources at all.
somehow I can’t get it to work… must be an error in the formula.
Isn’t there a way to set variable values outside this field so I can do small calculations and set values to variables that I can use in this field?
Sort of breaking it up in smaller pieces.
Also I get quotation marks around my formula when I go back into the editor (click the lightning flash) and then swith from design to code view…
I have set a value and change the data type to number
I save the file and come back to it and the value property data type is again set back to text (and another one to object)…?
The data type menu doesn’t change the actual data type. It tells the data picker and data formatter what data to expect.
Anyway this has been fixed in the latest update.
The error says some parts of the formula are not properly formatted. Probably using a string in some of the calculations.
I suggest to start debugging this by building the formula step by step and see which part is causing it.
It is possible to use it exactly like that.
Are you sure then that the api.data.last_sale.total_price is a number and not a string? How is it returned exactly by your API?
Oh i see now that you are using a POST var. Form inputs are always a string, so you need to use the to number formatter for the POST variable value, in order to convert it to number and to be able to make calculations.