Skip to main content

Hey Klaviyo team, 

I am wondering where I can find the return types for specific API queries? For instance I have the following “Create Client Subscription” operation, but I am manually typing out the return types:

interface CreateClientSubscription {
email?: string | null;
phone?: string | null;
status: number;
message: string;
error: string | null;
submittedAt: string;
}

/**
* Subscribes a user to a specified email list.
* @param email - The user's email address
* @param listId - The email list ID (newsletter)
* @returns A Promise resolving to the subscription data
* @see https://developers.klaviyo.com/en/reference/create_client_subscription
*/
const newsletter = async (
email: string,
listId: string
): Promise<CreateClientSubscription> => {
return await $fetch('/api/klaviyo', {
method: 'POST',
body: {
data: {
type: 'subscription',
attributes: {
profile: {
data: {
type: 'profile',
attributes: { email }
}
}
},
relationships: {
list: {
data: {
type: 'list',
id: listId
}
}
}
}
}
});
};

Ideally, it would be best to just import the pre-defined types into my Klaviyo operations. I am using codegen, but I dont think this can be done. Perhaps there is another repo/library I am missing?

Thanks!:)

@rylanharper Have you reviewed the SDKs? Links to the relevant GitHub repositories for specific programming languages can be found on this page: https://developers.klaviyo.com/en/docs/sdk_overview

 

The repository for Node.js integration is located at https://github.com/klaviyo/klaviyo-api-node. The methods and return types for each API endpoint have been organized accordingly. It appears that the Klaviyo engineering team utilized codegen tools as well.


Hey ​@whereisjad!

Thanks for the quick reply. These are really good resources to have. I took a look over the sdk and node api, but I didn’t quite find what I was looking for. I mainly only need the basic return types for specific types of queries. I am using the `create_client_subscription` and `create_client_back_in_stock_subscription` queries. Everything is working correctly on my end, but it would be good to have the proper type responses I can pass into my Promises.