Download the PHP package klaviyo/sdk without Composer
On this page you can find all versions of the php package klaviyo/sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sdk
Klaviyo PHP SDK (Legacy)
Legacy Notice
This SDK is set to be deprecated + retired on 2024-06-30.
We have a NEW PHP SDK to go along with our new API.
We recommend migrating over to our newest SDK.
You can read more about our SDK release history and support here
For a comparison between our old and new APIs, check out this guide.
Klaviyo PHP SDK
- SDK version: 1.0.3.20220329
Helpful Resources
Design & Approach
This SDK is a thin wrapper around our API. See our API Reference for full documentation on API behavior.
This SDK mirrors the organization and naming convention of the above language-agnostic resources, with a few namespace changes to conform to PHP idioms (details in Appendix).
Organization
This SDK is organized into the following resources:
-
Campaigns
-
DataPrivacy
-
ListsSegments
-
Metrics
-
Profiles
-
Templates
- TrackIdentify
Installation
You can install this package using either Packagist, or the source code.
Option 1: Packagist
You can install this library using Packagist.
If you have composer installed, you can run: composer require klaviyo/sdk
Option 2: Source code
You can also install this library directly from source code, without using the Packagist package, as follows:
- cloning this repo
- running
composer update
(within the repo)
Usage Example
Retry behavior
- The SDK retries on resolvable errors, namely: rate limits (common) and server errors on Klaviyo's end (rare).
- The keyword arguments in the example above define retry behavior
wait_seconds
denotes how long to wait per retry, in seconds- If you wish to disable retries, set
$num_retries = 0
- the example is populated with the default values
- non-resolvable errors and resolvable errors which have timed out throw an
ApiException
, detailed below.
Error Handling
This SDK throws an ApiException
error when the server returns a non resolvable response, or a resolvable non-2XX
response times out.
If you'd like to extend error handling beyond what the SDK supports natively, you can use the following methods to retrieve the corresponding attributes from the ApiException
object:
getCode() : int
getMessage() : str
getReponseBody() : bytes
getResponseHeaders() : string[]
For example:
Comprehensive list of Operations & Parameters
NOTE:
- Organization: Resource groups and functions are listed in alphabetical order, first by Resource name, then by OpenAPI Summary. Operation summaries are those listed in the right side bar of the API Reference. These summaries link directly to the corresponding section of the API reference.
- For example values / data types, as well as whether parameters are required/optional, please reference the corresponding API Reference link.
- Some keyword args are required for the API call to succeed, the API docs above are the source of truth regarding which keyword args are required.
- Keyword args are not included in the sample SDK calls; instead, where applicable, they are included as comments above each SDK call.
- JSON payloads should be passed in as associative arrays
- A strange quirk of PHP is that default/optional arguments must be passed in in order, and MUST be included and set as
null
, at least up to the last default value you wish to use.- For example, if a given function has the following optional parameters
someFunction($a=1, $b=2, $c=3)
, and you wish to only set$b
, you MUST pass insomeFunction($a=null, $b=$YOUR_VALUE)
- Otherwise, if you pass in something such as
someFunction($b=$YOUR_VALUE)
, PHP will actually assign the$YOUR_VALUE
to parameter$a
, which is wrong.
- For example, if a given function has the following optional parameters
Campaigns
Cancel a Campaign
Clone a Campaign
Create New Campaign
Get Campaign Info
Get Campaign Recipients
Get Campaigns
Schedule a Campaign
Send a Campaign Immediately
Update Campaign
DataPrivacy
Request a Deletion
ListsSegments
Add Members to a List
Create List
Delete List
Exclude Profile From All Email
Get Global Exclusions & Unsubscribes
Get All Exclusions for a List
Get List Info
Check if Profiles Are in a List
Check if Profiles Are in a List and not Suppressed
Get Lists
Get List and Segment Members
Check if Profiles Are in a Segment
Remove Profiles From List
Subscribe Profiles to List
Unsubscribe Profiles From List
Update List Name
Metrics
Get Metrics Info
Query Event Data
Get Events for a Specific Metric
Get Events for All Metrics
Profiles
Exchange ID for Profile ID
Get Profile
Get Profile ID
Get Profile's Events for a Specific Metric
Get Profile's Events for all Metrics
Update Profile
Templates
Clone Template
Create New Template
Delete Template
Get All Templates
Render Template
Render and Send Template
Update Template
TrackIdentify
Identify Profile (Legacy)
Identify Profile
Track Profile Activity (Legacy)
Track Profile Activity
Appendix
Limitations
- The
api_key
is set at the global level: this means that if you manage multiple stores, you will need to run the code for each store in a different environment
Namespace
In the interest of making the SDK conform to PHP idioms, we made the following namespace changes relative to the language agnostic resources up top (API Docs, Guides, etc).
- non-alphanumeric symbols (spaces, dashes, underscore, ampersand etc) stripped from resource names (tags) and function names (operation IDs)
- Resource names and function names use camelCase
- NOTE: this does not apply to parameter names
For example:
Track & Identify
becomesTrackIdentify
get-campaigns
becomesgetCampaigns
profile_id
remains unchanged
Parameters & Arguments
The parameters follow the same naming conventions as the resource groups and operations.
We stick to the following convention for parameters/arguments
- All parameters are passed as function args.
- All optional params, as well as all Body and Form Data params (including required ones), are passed as keyword args.
- All query and path params that are tagged as
required
in the docs are passed as positional args. - There is no need to pass in your private
api_key
for any operations, as it is defined upon client instantiation; public key is still required where noted for Track/Identify endpoints.
All versions of sdk with dependencies
ext-curl Version *
ext-json Version *
ext-mbstring Version *
guzzlehttp/guzzle Version ^7.3
guzzlehttp/psr7 Version ^1.7 || ^2.0