Closed maxsynnott closed 1 year ago
Its yucky (looks like there are some gaps in Klaviyo's OpenAPI definition or there is an issue with the code generator), but I was able to get a minimal typescript client going with this (once I used find/replace to fix 90 TS compile errors, but I also was integrating into a lerna monorepo with newer version of TS, etc. so YMMV)
curl -X POST \
https://generator3.swagger.io/api/generate \
-H 'content-type: application/json' \
-d '{
"specURL" : "https://klaviyo-openapi.s3.amazonaws.com/spec.json",
"lang" : "typescript-axios",
"type" : "CLIENT",
"codegenVersion" : "V3"
}' --output ~/Downloads/klaviyo.zip
The Typescript support is pretty basic, because all of the interesting bits of the request end up being JSON.stringify
ied, but its better than nothing:
import { TrackIdentifyApi } from '@faredrop/klayvio'
const trackIdentify = new TrackIdentifyApi({
apiKey: 'pk_1234...'
})
const response = await trackIdentify.identifyPost(JSON.stringify({
"token": ".....",
"properties": {
"$email": "abraham.lincoln@klaviyo.com",
"$first_name": "Abraham",
"$last_name": "Lincoln",
"$city": "Springfield",
"$region": "Illinois"
}
}))
console.log(`success === ${response.data === '1'}`);
@deldrid1 do you have this published anywhere?
A typescript SDK is in progress for our new apis. For now I suggest taking a look at the new node sdk and it's discussion about typescript (The objects for the new sdk are much more consistent)
Read our Migrating from V1/V2 to the new Klaviyo APIs and Comparison between v1/v2 and new APIs.
Typescript is in open beta check it out here.
Hello,
Do you intend to add Typescript support? I think it would be a mistake not to.