Skip to main content

I'm encountering an issue with integrating the timestamp in Klaviyo using the new API:
 

The date-time field appears to be passed correctly, but Klaviyo displays only the current date without the exact time. Example:

  • Activity details: Timestamped at 2024-10-30T00:00:00Z and recorded on 2024-10-30T07:08:55Z.

I've tried multiple date functions, including gmdate("Y-m-d\TH:i:s\Z"), (new DateTime("now", new DateTimeZone("UTC")))->format("Y-m-d\TH:i:s\Z"), and (new DateTime("now", new DateTimeZone("UTC")))->format("c"). However, I keep receiving the error: "Historical email subscription does not have a valid consented_at timestamp" — despite passing "historical_import" => true as required.

Interestingly, if I hardcode the date with a timestamp like "2023-10-30T07:16:47Z", the data passes without issues.


Since I’ve been using Klaviyo integrations for years without this issue, I believe it may relate to recent API updates. Any insights on how to ensure the exact time is passed and recorded accurately? Thank you!

API Endpoint: https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs/

$requestDatat'data'] = '
    "type" => "profile-subscription-bulk-create-job",
    "attributes" => s
        "profiles" => f
            "data" => Â
               
                    "type" => "profile",
                    "attributes" =>
                        "email" => $email,
                        "subscriptions" => $
                            "email" => "
                                "marketing" =>  
                                    "consent" => "SUBSCRIBED",
                                    "consented_at" => date("Y-m-d")
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ],
        "historical_import" => true
    ],
    "relationships" =>  
        "list" =>  
            "data" =>
                "type" => "list",
                "id" => $listId
            ]
        ]
    ]
];

@dev_wheelify - not sure if you figured this out yet, but if the hard-coded string passes, then it sounds like your various date functions are not returning what you think they are, or are malformed, or not the right data type (is it returning a Date Object instead of a String?) 

This looks like PHP code, so I’m not super familiar with the various date format code parameters (though they look the same as Python/C format codes). Have you tried isolating out the date string like this:

$timestamp = (new DateTime('now', new DateTimeZone('UTC')))->format('Y-m-d\TH:i:s\Z');

And then use $timestamp in its proper place?  You may want to output the $timestamp to console to verify that it is a string (and not an object - or if it is an object, you have to stringify it).  Again, I’m no PHP expert so I leave you to test/iterate.  Good luck!


Reply