Download the PHP package klaviyo/api without Composer
On this page you can find all versions of the php package klaviyo/api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package api
Short Description PHP SDK for Klaviyo's API.
License MIT
Homepage https://developers.klaviyo.com
Informations about the package api
Klaviyo PHP SDK
- SDK version: 7.1.2
- API Revision: 2024-02-15
Helpful Resources
Design & Approach
This SDK is a thin wrapper around our API. See our API Reference for full documentation on 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:
-
Accounts
-
Campaigns
-
Catalogs
-
Coupons
-
DataPrivacy
-
Events
-
Flows
-
Images
-
Lists
-
Metrics
-
Profiles
-
Reporting
-
Segments
-
Tags
- Templates
Installation
You can install this package using our Packagist package:
Usage Example
Use Case Examples
How to use filtering, sorting, and spare fieldset JSON API features
Use Case: Get events associated with a specific metric, then return just the event properties sorted by oldest to newest datetime.
NOTE: the filter param values need to be url-encoded
How to filter based on datetime
Use Case: Get profiles that have been updated between two datetimes.
How to use pagination and the page[size] param
Use Case: Use cursor-based pagination to get the next 20 profile records.
NOTE: This page cursor value is exactly what is returned in the self
/next
/prev
response values
How to add additional information to your API response via additional-fields and the includes
parameter
Use Case: Get a specific profile, return an additional predictive analytics field, and also return the list objects associated with the profile.
How to use our relationship endpoints to see related resources
Use Case: Get all list memberships for a profile with the given profile_id
.
How to see what Klaviyo objects are associated with a specific tag
Use Case: Get all campaigns associated with the given tag_id
.
Uploading Image From File
When using Images.uploadImageFromFile(file, name=name)
, `file`` can be either a file path string OR a bytearray.
NOTE: when file is a bytearray, you will need to use the optional name
parameter to specify the file name, else name will default to unnamed_image_from_python_sdk
as a file path
as a bytearray
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
getResponseBody() : bytes
getResponseHeaders() : string[]
For example:
Important Notes
- The main difference between this SDK and the language-agnostic API Docs that the below endpoints link to is that this SDK automatically adds the
revision
header corresponding to the SDK version. - 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.
- 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
$api_key
is optional, as it is set at client-level. However, you can override the client key wherever by passing in$api_key
as the LAST optional param. Reminder: DO NOT use private API keys client-side / onsite.- Paging: Where applicable,
$page_cursor
can be passed in either as a parsed string, or as the entireself.link
response returned by paged API endpoints.
Comprehensive list of Operations & Parameters
Accounts
Get Account
Get Accounts
Campaigns
Create Campaign
Create Campaign Clone
Assign Campaign Message Template
Create Campaign Recipient Estimation Job
Create Campaign Send Job
Delete Campaign
Get Campaign
Get Campaign Campaign Messages
Get Campaign Message
Get Campaign Message Campaign
Get Campaign Message Relationships Campaign
Get Campaign Message Relationships Template
Get Campaign Message Template
Get Campaign Recipient Estimation
Get Campaign Recipient Estimation Job
Get Campaign Relationships Campaign Messages
Get Campaign Relationships Tags
Get Campaign Send Job
Get Campaign Tags
Get Campaigns
Update Campaign
Update Campaign Message
Update Campaign Send Job
Catalogs
Create Back In Stock Subscription
Create Catalog Category
Create Catalog Category Relationships Items
Create Catalog Item
Create Catalog Item Relationships Categories
Create Catalog Variant
Delete Catalog Category
Delete Catalog Category Relationships Items
Delete Catalog Item
Delete Catalog Item Relationships Categories
Delete Catalog Variant
Get Catalog Categories
Get Catalog Category
Get Catalog Category Items
Get Catalog Category Relationships Items
Get Catalog Item
Get Catalog Item Categories
Get Catalog Item Relationships Categories
Get Catalog Item Variants
Get Catalog Items
Get Catalog Variant
Get Catalog Variants
Get Create Categories Job
Get Create Categories Jobs
Get Create Items Job
Get Create Items Jobs
Get Create Variants Job
Get Create Variants Jobs
Get Delete Categories Job
Get Delete Categories Jobs
Get Delete Items Job
Get Delete Items Jobs
Get Delete Variants Job
Get Delete Variants Jobs
Get Update Categories Job
Get Update Categories Jobs
Get Update Items Job
Get Update Items Jobs
Get Update Variants Job
Get Update Variants Jobs
Spawn Create Categories Job
Spawn Create Items Job
Spawn Create Variants Job
Spawn Delete Categories Job
Spawn Delete Items Job
Spawn Delete Variants Job
Spawn Update Categories Job
Spawn Update Items Job
Spawn Update Variants Job
Update Catalog Category
Update Catalog Category Relationships Items
Update Catalog Item
Update Catalog Item Relationships Categories
Update Catalog Variant
Coupons
Create Coupon
Create Coupon Code
Delete Coupon
Delete Coupon Code
Get Coupon
Get Coupon Code
Get Coupon Code Bulk Create Job
Get Coupon Code Bulk Create Jobs
Get Coupon Code Relationships Coupon
Get Coupon Codes
Get Coupon Codes For Coupon
Get Coupon For Coupon Code
Get Coupon Relationships Coupon Codes
Get Coupons
Spawn Coupon Code Bulk Create Job
Update Coupon
Update Coupon Code
DataPrivacy
Request Profile Deletion
Events
Create Event
Get Event
Get Event Metric
Get Event Profile
Get Event Relationships Metric
Get Event Relationships Profile
Get Events
Flows
Get Flow
Get Flow Action
Get Flow For Flow Action
Get Flow Action Messages
Get Flow Action Relationships Flow
Get Flow Action Relationships Messages
Get Flow Flow Actions
Get Flow Message
Get Flow Action For Message
Get Flow Message Relationships Action
Get Flow Message Relationships Template
Get Flow Message Template
Get Flow Relationships Flow Actions
Get Flow Relationships Tags
Get Flow Tags
Get Flows
Update Flow Status
Images
Get Image
Get Images
Update Image
Upload Image From File
Upload Image From URL
Lists
Create List
Add Profile To List
Delete List
Remove Profile From List
Get List
Get List Profiles
Get List Relationships Profiles
Get List Relationships Tags
Get List Tags
Get Lists
Update List
Metrics
Get Metric
Get Metrics
Query Metric Aggregates
Profiles
Create or Update Profile
Create Profile
Create or Update Push Token
Get Bulk Profile Import Job
Get Bulk Profile Import Job Errors
Get Bulk Profile Import Job Lists
Get Bulk Profile Import Job Profiles
Get Bulk Profile Import Job Relationships Lists
Get Bulk Profile Import Job Relationships Profiles
Get Bulk Profile Import Jobs
Get Profile
Get Profile Lists
Get Profile Relationships Lists
Get Profile Relationships Segments
Get Profile Segments
Get Profiles
Merge Profiles
Spawn Bulk Profile Import Job
Subscribe Profiles
Suppress Profiles
Unsubscribe Profiles
Unsuppress Profiles
Update Profile
Reporting
Query Campaign Values
Query Flow Series
Query Flow Values
Segments
Get Segment
Get Segment Profiles
Get Segment Relationships Profiles
Get Segment Relationships Tags
Get Segment Tags
Get Segments
Update Segment
Tags
Create Tag
Create Tag Group
Create Tag Relationships Campaigns
Create Tag Relationships Flows
Create Tag Relationships Lists
Create Tag Relationships Segments
Delete Tag
Delete Tag Group
Delete Tag Relationships Campaigns
Delete Tag Relationships Flows
Delete Tag Relationships Lists
Delete Tag Relationships Segments
Get Tag
Get Tag Group
Get Tag Group Relationships Tags
Get Tag Group Tags
Get Tag Groups
## Keyword Arguments
# $fields_tag_group | string[]
# $filter | string
# $page_cursor | string
# $sort | string
$klaviyo->Tags->getTagGroups($fields_tag_group=$fields_tag_group, $filter=$filter, $page_cursor=$page_cursor, $sort=$sort);
Get Tag Relationships Campaigns
## Positional Arguments
# $id | string
$klaviyo->Tags->getTagRelationshipsCampaigns($id);
Get Tag Relationships Flows
## Positional Arguments
# $id | string
$klaviyo->Tags->getTagRelationshipsFlows($id);
Get Tag Relationships Lists
## Positional Arguments
# $id | string
$klaviyo->Tags->getTagRelationshipsLists($id);
Get Tag Relationships Segments
## Positional Arguments
# $id | string
$klaviyo->Tags->getTagRelationshipsSegments($id);
Get Tag Relationships Tag Group
## Positional Arguments
# $id | string
$klaviyo->Tags->getTagRelationshipsTagGroup($id);
Get Tag Tag Group
## Positional Arguments
# $id | string
## Keyword Arguments
# $fields_tag_group | string[]
$klaviyo->Tags->getTagTagGroup($id, $fields_tag_group=$fields_tag_group);
Get Tags
## Keyword Arguments
# $fields_tag_group | string[]
# $fields_tag | string[]
# $filter | string
# $include | string[]
# $page_cursor | string
# $sort | string
$klaviyo->Tags->getTags($fields_tag_group=$fields_tag_group, $fields_tag=$fields_tag, $filter=$filter, $include=$include, $page_cursor=$page_cursor, $sort=$sort);
Update Tag
## Positional Arguments
# $id | string
# $body | associative array
$klaviyo->Tags->updateTag($id, $body);
Update Tag Group
## Positional Arguments
# $id | string
# $body | associative array
$klaviyo->Tags->updateTagGroup($id, $body);
Templates
Create Template
## Positional Arguments
# $body | associative array
$klaviyo->Templates->createTemplate($body);
Create Template Clone
## Positional Arguments
# $body | associative array
$klaviyo->Templates->createTemplateClone($body);
Create Template Render
## Positional Arguments
# $body | associative array
$klaviyo->Templates->createTemplateRender($body);
Delete Template
## Positional Arguments
# $id | string
$klaviyo->Templates->deleteTemplate($id);
Get Template
## Positional Arguments
# $id | string
## Keyword Arguments
# $fields_template | string[]
$klaviyo->Templates->getTemplate($id, $fields_template=$fields_template);
Get Templates
## Keyword Arguments
# $fields_template | string[]
# $filter | string
# $page_cursor | string
# $sort | string
$klaviyo->Templates->getTemplates($fields_template=$fields_template, $filter=$filter, $page_cursor=$page_cursor, $sort=$sort);
Update Template
## Positional Arguments
# $id | string
# $body | associative array
$klaviyo->Templates->updateTemplate($id, $body);
Appendix
Global Keyword args
NOTES:
- These are arguments that you can apply to any endpoint call, and which are unique to the SDK.
- They come LAST, AFTER ALL the endpoint-specific keyword args listed above, in the same order they are listed below.
- They are subject to the same quirks as any other PHP keyword args, in that to be included, they need to be preceeded by all keyword args listed before them. This includes all endpoint-specific keyword args for a given endpoint, along with any preceeding global keyword args listed below, if applicable. This holds even if those other keyword args are not being used; in that case, set those to
null
, but again, they must be included.
We currently support the following global keyword args:
$apiKey
: use this to override the client-levelapi_key
, which you define upon client instantiation.
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).
- Underscores are stripped from function names (operation IDs)
- Function names use camelCase (e.g.
getMetrics
) - Resource names use PascalCase (e.g.
Metrics
) - Parameter names remain unchanged
Parameters & Arguments
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. $api_key
is optional, as it is set at client level. However, you can override the client key wherever by passing in$api_key
as the LAST optional param. Reminder: don't do this client-side.
All versions of api with dependencies
ext-curl Version *
ext-json Version *
ext-mbstring Version *
guzzlehttp/guzzle Version ^7.3
guzzlehttp/psr7 Version ^1.7 || ^2.0