Skip to content

HeuHax/KlaviyoSharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KlaviyoSharp

Build & Test GitHub GitHub issues GitHub last commit (branch)

Nuget Nuget

KlaviyoSharp is a .NET Standard 2.0 library that enables you to interact with the Klaviyo API in .NET. This project was started as there was no fully fleshed out and updated package available to interact with the Klaviyo API in .NET.

Installation

KlaviyoSharp is available on NuGet and is updated via CI/CD. To install KlaviyoSharp, run the following command in the Package Manager Console:

Install-Package KlaviyoSharp

API Support

Klaviyo's API is versioned by using dates in the request headers. The mapping of these to this package is as follows:

Klaviyo API Version KlaviyoSharp Version
2024-02-15 1.2.x
2023-07-15 1.1.x
2023-06-15 1.0.x

How to Use

//Setup the config and client
var config = new KlaviyoConfig("Api-Key-Goes-Here");
var client = new KlaviyoAdminApi(config);

//You can also directly pass in the API key to the client
client = new KlaviyoAdminApi("Api-Key-Goes-Here");

//The public client doesn't use an API key, just a company ID
var publicClient = new KlaviyoClientApi("Company-ID-Goes-Here");

//Create filter for listing objects. Filters added to a FilterList are ANDed together.
var filter1 = new Filter(FilterOperation.Equals, "email", "test@example.com");
var filter2 = new Filter(FilterOperation.LessThan, "last_updated", DateOnly.Parse("2021-01-01"));
var filters = new FilterList() { filter1, filter2 };

//Retrieve profiles using the filter. All API calls are async.
var profiles = client.ProfileServices.GetProfiles(filter: filters, sort: "last_updated").Result;

//Returned lists are wrapped in a DataListObject class. The Data property contains the list of objects.
foreach (var profile in profiles.Data)
{
    Console.WriteLine(profile.Id);
}

//Create a new profile - Using the Create method sets the required default properties.
var newProfile = Profile.Create();
newProfile.Attributes = new()
{
    FirstName = "Test",
    LastName = "User",
    Email = "testing@example.com"
};
var createdProfile = client.ProfileServices.CreateProfile(newProfile).Result;

//Returned single items are wrapped in a DataObject class. The Data property contains the object.
Console.WriteLine(createdProfile.Data.Id);

Contributing

Checkout the contributing guide for more information on how to contribute to this project.

Thankyou

Thanks to @nozzlegear for the inspiration to create this package based roughly on his ShopifySharp package.

About

Klaviyo API Nuget Package

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%