Forum Discussion
Liquid Date Formatting for API-Triggered Properties
I'm trying to format the date and time on our transactional appt confirmation emails. I found a formula that worked perfectly when I used a date field from Braze, but when I plug this same formula in with a property from an API trigger, it doesn't work.
Here's the liquid logic and output for a custom attribute date field stored on the user profile (correct result):
And here's the liquid script used with the API-triggered property and the output I get with that one (incorrect result):
Does anyone know what might be causing this?
- ArsoExpert
Hi! Can you post the input date for both types of attributes, before the date filter is performed?
I tried this with both custom attributes and api trigger properties and I get the same result for both. As in, the right output prints in both cases, when using those date references.
It could be the original format of the date. You could try testing with the original inputs and if you still encounter the issue - try assigning both to new variables, instead of applying the date filter directly on the property.- kayla_uptonInfluencer
The mly_first_job_date custom attribute is a Time field and both the job_promise_date and job_promise_time fields from the API properties are datetime2(7).
Let me know if that helps!- ArsoExpert
While the type might be datetime2 on the server side, the format it's in when it hits Braze MM/DD/YYYY is unsupported by the liquid date filter. The output you see is actually the input - none of the date operations you did with liquid were performed.
Ideally, you would reformat it in the backend and send it to Braze in an appropriate format. However, if you can't do that or if it takes too much time, here's a quick fix in Braze.You need to add this in the template. At the time the message is triggered, the code will reformat the variable to a date format accepted by liquid.
{% assign datevars = {{api_trigger_properties.${job_promise_date} | split: "/" }} %} {% assign monthsize = datevars[0] | size %} {% if monthsize == 1 %} {% assign month = datevars[0] | prepend: "0" %} {% else %} {% assign month = datevars[0] %} {% endif %} {% assign job_promise_date = datevars[2] | append: "-" | append: month | append: "-" | append: datevars[1] | date: "%A, %B %e, %Y" %} {{job_promise_date }}
I'm not sure why the time liquid doesn't work though. I tried adding the same input and it worked for me. It would be helpful if you had logs of those API calls to see the actual values that are being passed.
- AllanHeoFNMVisionary
Arsoprovided some great feedback already, but here are some thoughts in slightly different color:
- I have a feeling that when the date value is stored in Braze as a Custom Attribute, Braze is a bit more flexible with different date formats and is recognizing your current date format as a Date datatype
- But when you’re inserting data directly as an API trigger property, it’s not getting the same flexible treatment as your Custom Attributes. And Braze does recommend iso8601 (YYYY-MM-DD…) format for date variables.
Your Liquid looks fine and should treat both outcomes the same, but I always like to see how the original value is rendered when debugging.
So just rendering your CA and your API trigger properties with any date filter applied would be a great first step!
And we would suggest altering the way the data comes into Braze instead of using Liquid to manipulate the date format… but if you do go the latter route, Arso looks like he did the hard part for us already!
- kayla_uptonInfluencer
Thank you! I'm going to try out this workaround for now since our IT backlog could take months to get in the queue. One question - I see that the conditional statement includes a way to format the date field with the day of week, day of month, and year. However, is there a different solution to change the {job_promise_time} field to a standard 1:00pm format so it isn't displaying in military time?
I didn't see a solution for that value, only the day of the appointment.
Related Content
- 4 months ago
- 2 years ago
- 2 years ago