I’m running into what appears to be an issue with Bubble’s API Connector when converting nested Unix timestamps from the Stripe API into Bubble Date fields.
I’m using the Stripe Get Subscription endpoint. The response contains an items.data list, and each subscription item contains created, current_period_start, and current_period_end Unix timestamps. In the API Connector, I changed all three fields to the Date data type and reinitialized the API.
The API initializes correctly and shows valid Unix timestamps. For example, current_period_start = 1783741936 and current_period_end = 1786420336, which are the expected values.
However, when I save these values into Date fields in my User table via a backend workflow, current_period_start, current_period_end, and created all save as January 21, 1970 instead of the correct dates.
What’s confusing is that other Unix timestamp fields from the same Stripe integration work perfectly. For example, trial_end and subscription_last_updated_date are both stored correctly as Date fields. This makes me think Bubble can handle Unix timestamps correctly in general, but something is different about these particular fields.
To troubleshoot, I’ve:
- Verified Stripe is returning the correct Unix values.
- Changed the API fields to Date and reinitialized the API.
- Deleted and rebuilt the workflow expressions from scratch.
- Confirmed the database fields are all type Date.
- Verified that the problem only occurs with these specific fields.
Has anyone experienced Bubble incorrectly converting Unix timestamps that are nested inside a list (such as items.data)? Is this a known API Connector limitation or bug, or is there a better way to reference these fields?
One other note: these UNIX timestamps seem to be treated as milliseconds instead of seconds. For example, 1783741936 ends up as approximately Jan. 21, 1970. Could this be a Bubble API Connector issue? Has anyone found a workaround, such as multiplying the value by 1000 before converting it to a date? I also haven’t found a reliable way to convert UNIX timestamps to Bubble Date fields, so any suggestions would be appreciated.
Bubble store’s UNIX timestamps in (ms). You must do the conversions when dealing with APIs.
Thanks! Where is this expression used? It looks like Bubble’s “Extract from date” operator, which converts a Date to a Unix timestamp. My issue is the opposite—I have a Unix timestamp from Stripe that I need to convert into a Bubble Date. Is there an inverse function I’m missing?
If Bubble expects Unix timestamps in milliseconds but Stripe returns seconds, what’s the recommended way to convert a Unix timestamp from an API into a Bubble Date? Is there a native conversion, or does everyone multiply by 1000 first? If so, where do you perform that conversion?
Doing some more experimentation: In the API Connector I’ve set several Stripe Unix timestamp fields (trial_end, current_period_start, current_period_end) to Date and reinitialized the call. However, in my workflow some of these fields are still treated as the wrong type (e.g. they appear red when assigning to a Date field), while others can be assigned but save as Jan. 21, 1970. Has anyone seen the API Connector cache or expose an incorrect internal field type even after reinitializing?
Another new test. I rebuilt the API and tested it fresh. It still returns dates in 1970, this time including trial_end. I recall there used to be a field in the API builder where you can set the field to date (unix). I no longer have that option in my list. Is this a bug or something else?
Well, I never figured out the problem, but a simple unix conversion plugin did manage to work after all. So fuck it.
Yeah, Stripe u have to use a plugin or server side js (via toolbox plugin) because they return in seconds not ms if I recall correctly.