Really weird behaviour here that I can’t get to the bottom of; I have a method which I use to render klaviyo templates, and use this in several projects with no issue. However, in our most recent I’m getting a 400 error on the API call - despite the identical call on Postman working and getting a response.
I’ve verified that the Authorization header, indeed all headers, match the Postman call for my own sanity (they do), and have even just reduced the context down to a single key/value pair to ensure there’s nothing weird going on with content.
However, the 400 issue persists; if I switch on enhanced logging I get the following:
* Trying 2606:4700:4400::ac40:9377:443...
* Connected to a.klaviyo.com (2606:4700:4400::ac40:9377) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=a.klaviyo.com
* start date: Jul 22 05:46:38 2024 GMT
* expire date: Oct 20 05:46:37 2024 GMT
* subjectAltName: host "a.klaviyo.com" matched cert's "a.klaviyo.com"
* issuer: C=US; O=Google Trust Services; CN=WE1
* SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5568b69836f0)
> post /api/template-render HTTP/2
Host: a.klaviyo.com
authorization: Klaviyo-API-Key pk_xxx
accept: application/json
content-type: application/json
revision: 2024-07-15
content-length: 108
* We are completely uploaded and fine
* old SSL session ID is stale, removing
< HTTP/2 400
< server: cloudflare
< date: Thu, 22 Aug 2024 09:57:51 GMT
< content-type: text/html
< content-length: 155
< cf-ray: -
* The requested URL returned error: 400
* stopped the pause stream!
* Connection #0 to host a.klaviyo.com left intact
For completeness, here are my headers and body:
INFO - 2024-08-22 11:08:12 --> Header: Authorization: Authorization: Klaviyo-API-Key pk_xxx
INFO - 2024-08-22 11:08:12 --> Header: Accept: Accept: application/json
INFO - 2024-08-22 11:08:12 --> Header: Content-Type: Content-Type: application/json
INFO - 2024-08-22 11:08:12 --> Header: revision: revision: 2024-07-15
{
"data": {
"type": "template",
"id": "US2baB",
"attributes": {
"context": {
"salutation": "Hi Test",
"detail": "TEST"
}
}
}
}
As I mentioned, the method I have is identical in 3 other projects and works no problem there, so I’m a bit stumped as to why this time it’s working in Postman (so not an auth or formatting issue) but not in my project.