Coder Social home page Coder Social logo

klaviyo / klaviyo-api-php Goto Github PK

View Code? Open in Web Editor NEW
36.0 7.0 18.0 1.15 MB

PHP SDK for Klaviyo API

Home Page: https://developers.klaviyo.com

License: MIT License

PHP 100.00%
bigcommerce ecommerce email klaviyo magento notifications prestashop push sfcc shopify

klaviyo-api-php's Introduction

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:

composer require klaviyo/api

Usage Example

<?php
require_once(__DIR__ . '/vendor/autoload.php');

use KlaviyoAPI\KlaviyoAPI;

$klaviyo = new KlaviyoAPI(
    'YOUR_API_KEY', 
    $num_retries = 3, 
    $wait_seconds = 3,
    $guzzle_options = [],
    $user_agent_suffix = "/YOUR_APP_NAME");

$response = $klaviyo->Metrics->getMetrics();

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.

$klaviyo->Events->getEvents(
    $fields_event=['event_properties'], 
    $fields_metric=NULL, 
    $fields_profile=NULL, 
    $filter="equals(metric_id,\"UMTLbD\")", 
    $include=NULL, 
    $page_cursor=NULL, 
    $sort='-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.

$klaviyo->Profiles->getProfiles(
    $additional_fields_profile=NULL, 
    $fields_profile=NULL, 
    $filter='less-than(updated,2023-04-26T00:00:00Z),greater-than(updated,2023-04-19T00:00:00Z)', 
);

How to use pagination and the page[size] param

Use Case: Use cursor-based pagination to get the next 20 profile records.

$klaviyo->Profiles->getProfiles(
    $additional_fields_profile=NULL, 
    $fields_profile=NULL, 
    $filter=NULL,
    $page_cursor="https://a.klaviyo.com/api/profiles/?page%5Bcursor%5D=bmV4dDo6aWQ6OjAxRjNaWk5ITlRYMUtFVEhQMzJTUzRBN0ZY", 
    $page_size=20, 
);

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.

$klaviyo->Profiles->getProfile(
    '01F3ZZNHPY4YZFVGNBH5THCNXE', 
    $additional_fields_profile=['predictive_analytics'], 
    $fields_list=NULL, 
    $fields_profile=NULL, 
    $fields_segment=NULL, 
    $include=['lists']
);

How to use our relationship endpoints to see related resources

Use Case: Get all list memberships for a profile with the given profile_id.

$klaviyo->Profiles->getProfileRelationshipsLists('01GDDKASAP8TKDDA2GRZDSVP4H');

How to see what Klaviyo objects are associated with a specific tag

Use Case: Get all campaigns associated with the given tag_id.

$klaviyo->Tags->getTagRelationshipsCampaigns('f4bc6670-1aa5-47df-827a-d30a7e543088');

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

filepath = '/path/to/image.png'
klaviyo.Images.upload_image_from_file(file, name=name)

as a bytearray

filepath = '/path/to/image.png'
with open(filepath, 'rb') as f:
    file = f.read()
klaviyo.Images.upload_image_from_file(file, name=name)

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:

try { 
  $klaviyo.Metrics.getMetrics();
} catch (Exception $e) {
  if ($e->getCode() == SOME_INTEGER) {
    doSomething();
  }
}

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 in someFunction($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.
  • $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 entire self.link response returned by paged API endpoints.

Comprehensive list of Operations & Parameters

Accounts

## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_account | string[]

$klaviyo->Accounts->getAccount($id, $fields_account=$fields_account);
## Keyword Arguments

# $fields_account | string[]

$klaviyo->Accounts->getAccounts($fields_account=$fields_account);

Campaigns

## Positional Arguments

# $body | associative array

$klaviyo->Campaigns->createCampaign($body);
## Positional Arguments

# $body | associative array

$klaviyo->Campaigns->createCampaignClone($body);
## Positional Arguments

# $body | associative array

$klaviyo->Campaigns->createCampaignMessageAssignTemplate($body);
## Positional Arguments

# $body | associative array

$klaviyo->Campaigns->createCampaignRecipientEstimationJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Campaigns->createCampaignSendJob($body);
## Positional Arguments

# $id | string

$klaviyo->Campaigns->deleteCampaign($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_campaign_message | string[]
# $fields_campaign | string[]
# $fields_tag | string[]
# $include | string[]

$klaviyo->Campaigns->getCampaign($id, $fields_campaign_message=$fields_campaign_message, $fields_campaign=$fields_campaign, $fields_tag=$fields_tag, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_campaign_message | string[]
# $fields_campaign | string[]
# $fields_template | string[]
# $include | string[]

$klaviyo->Campaigns->getCampaignCampaignMessages($id, $fields_campaign_message=$fields_campaign_message, $fields_campaign=$fields_campaign, $fields_template=$fields_template, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_campaign_message | string[]
# $fields_campaign | string[]
# $fields_template | string[]
# $include | string[]

$klaviyo->Campaigns->getCampaignMessage($id, $fields_campaign_message=$fields_campaign_message, $fields_campaign=$fields_campaign, $fields_template=$fields_template, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_campaign | string[]

$klaviyo->Campaigns->getCampaignMessageCampaign($id, $fields_campaign=$fields_campaign);
## Positional Arguments

# $id | string

$klaviyo->Campaigns->getCampaignMessageRelationshipsCampaign($id);
## Positional Arguments

# $id | string

$klaviyo->Campaigns->getCampaignMessageRelationshipsTemplate($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_template | string[]

$klaviyo->Campaigns->getCampaignMessageTemplate($id, $fields_template=$fields_template);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_campaign_recipient_estimation | string[]

$klaviyo->Campaigns->getCampaignRecipientEstimation($id, $fields_campaign_recipient_estimation=$fields_campaign_recipient_estimation);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_campaign_recipient_estimation_job | string[]

$klaviyo->Campaigns->getCampaignRecipientEstimationJob($id, $fields_campaign_recipient_estimation_job=$fields_campaign_recipient_estimation_job);
## Positional Arguments

# $id | string

$klaviyo->Campaigns->getCampaignRelationshipsCampaignMessages($id);
## Positional Arguments

# $id | string

$klaviyo->Campaigns->getCampaignRelationshipsTags($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_campaign_send_job | string[]

$klaviyo->Campaigns->getCampaignSendJob($id, $fields_campaign_send_job=$fields_campaign_send_job);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_tag | string[]

$klaviyo->Campaigns->getCampaignTags($id, $fields_tag=$fields_tag);
## Positional Arguments

# $filter | string

## Keyword Arguments

# $fields_campaign_message | string[]
# $fields_campaign | string[]
# $fields_tag | string[]
# $include | string[]
# $page_cursor | string
# $sort | string

$klaviyo->Campaigns->getCampaigns($filter, $fields_campaign_message=$fields_campaign_message, $fields_campaign=$fields_campaign, $fields_tag=$fields_tag, $include=$include, $page_cursor=$page_cursor, $sort=$sort);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Campaigns->updateCampaign($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Campaigns->updateCampaignMessage($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Campaigns->updateCampaignSendJob($id, $body);

Catalogs

## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->createBackInStockSubscription($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->createCatalogCategory($body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->createCatalogCategoryRelationshipsItems($id, $body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->createCatalogItem($body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->createCatalogItemRelationshipsCategories($id, $body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->createCatalogVariant($body);
## Positional Arguments

# $id | string

$klaviyo->Catalogs->deleteCatalogCategory($id);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->deleteCatalogCategoryRelationshipsItems($id, $body);
## Positional Arguments

# $id | string

$klaviyo->Catalogs->deleteCatalogItem($id);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->deleteCatalogItemRelationshipsCategories($id, $body);
## Positional Arguments

# $id | string

$klaviyo->Catalogs->deleteCatalogVariant($id);
## Keyword Arguments

# $fields_catalog_category | string[]
# $filter | string
# $page_cursor | string
# $sort | string

$klaviyo->Catalogs->getCatalogCategories($fields_catalog_category=$fields_catalog_category, $filter=$filter, $page_cursor=$page_cursor, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_catalog_category | string[]

$klaviyo->Catalogs->getCatalogCategory($id, $fields_catalog_category=$fields_catalog_category);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_catalog_item | string[]
# $fields_catalog_variant | string[]
# $filter | string
# $include | string[]
# $page_cursor | string
# $sort | string

$klaviyo->Catalogs->getCatalogCategoryItems($id, $fields_catalog_item=$fields_catalog_item, $fields_catalog_variant=$fields_catalog_variant, $filter=$filter, $include=$include, $page_cursor=$page_cursor, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $page_cursor | string

$klaviyo->Catalogs->getCatalogCategoryRelationshipsItems($id, $page_cursor=$page_cursor);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_catalog_item | string[]
# $fields_catalog_variant | string[]
# $include | string[]

$klaviyo->Catalogs->getCatalogItem($id, $fields_catalog_item=$fields_catalog_item, $fields_catalog_variant=$fields_catalog_variant, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_catalog_category | string[]
# $filter | string
# $page_cursor | string
# $sort | string

$klaviyo->Catalogs->getCatalogItemCategories($id, $fields_catalog_category=$fields_catalog_category, $filter=$filter, $page_cursor=$page_cursor, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $page_cursor | string

$klaviyo->Catalogs->getCatalogItemRelationshipsCategories($id, $page_cursor=$page_cursor);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_catalog_variant | string[]
# $filter | string
# $page_cursor | string
# $sort | string

$klaviyo->Catalogs->getCatalogItemVariants($id, $fields_catalog_variant=$fields_catalog_variant, $filter=$filter, $page_cursor=$page_cursor, $sort=$sort);
## Keyword Arguments

# $fields_catalog_item | string[]
# $fields_catalog_variant | string[]
# $filter | string
# $include | string[]
# $page_cursor | string
# $sort | string

$klaviyo->Catalogs->getCatalogItems($fields_catalog_item=$fields_catalog_item, $fields_catalog_variant=$fields_catalog_variant, $filter=$filter, $include=$include, $page_cursor=$page_cursor, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_catalog_variant | string[]

$klaviyo->Catalogs->getCatalogVariant($id, $fields_catalog_variant=$fields_catalog_variant);
## Keyword Arguments

# $fields_catalog_variant | string[]
# $filter | string
# $page_cursor | string
# $sort | string

$klaviyo->Catalogs->getCatalogVariants($fields_catalog_variant=$fields_catalog_variant, $filter=$filter, $page_cursor=$page_cursor, $sort=$sort);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_category_bulk_create_job | string[]
# $fields_catalog_category | string[]
# $include | string[]

$klaviyo->Catalogs->getCreateCategoriesJob($job_id, $fields_catalog_category_bulk_create_job=$fields_catalog_category_bulk_create_job, $fields_catalog_category=$fields_catalog_category, $include=$include);
## Keyword Arguments

# $fields_catalog_category_bulk_create_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getCreateCategoriesJobs($fields_catalog_category_bulk_create_job=$fields_catalog_category_bulk_create_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_item_bulk_create_job | string[]
# $fields_catalog_item | string[]
# $include | string[]

$klaviyo->Catalogs->getCreateItemsJob($job_id, $fields_catalog_item_bulk_create_job=$fields_catalog_item_bulk_create_job, $fields_catalog_item=$fields_catalog_item, $include=$include);
## Keyword Arguments

# $fields_catalog_item_bulk_create_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getCreateItemsJobs($fields_catalog_item_bulk_create_job=$fields_catalog_item_bulk_create_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_variant_bulk_create_job | string[]
# $fields_catalog_variant | string[]
# $include | string[]

$klaviyo->Catalogs->getCreateVariantsJob($job_id, $fields_catalog_variant_bulk_create_job=$fields_catalog_variant_bulk_create_job, $fields_catalog_variant=$fields_catalog_variant, $include=$include);
## Keyword Arguments

# $fields_catalog_variant_bulk_create_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getCreateVariantsJobs($fields_catalog_variant_bulk_create_job=$fields_catalog_variant_bulk_create_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_category_bulk_delete_job | string[]

$klaviyo->Catalogs->getDeleteCategoriesJob($job_id, $fields_catalog_category_bulk_delete_job=$fields_catalog_category_bulk_delete_job);
## Keyword Arguments

# $fields_catalog_category_bulk_delete_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getDeleteCategoriesJobs($fields_catalog_category_bulk_delete_job=$fields_catalog_category_bulk_delete_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_item_bulk_delete_job | string[]

$klaviyo->Catalogs->getDeleteItemsJob($job_id, $fields_catalog_item_bulk_delete_job=$fields_catalog_item_bulk_delete_job);
## Keyword Arguments

# $fields_catalog_item_bulk_delete_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getDeleteItemsJobs($fields_catalog_item_bulk_delete_job=$fields_catalog_item_bulk_delete_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_variant_bulk_delete_job | string[]

$klaviyo->Catalogs->getDeleteVariantsJob($job_id, $fields_catalog_variant_bulk_delete_job=$fields_catalog_variant_bulk_delete_job);
## Keyword Arguments

# $fields_catalog_variant_bulk_delete_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getDeleteVariantsJobs($fields_catalog_variant_bulk_delete_job=$fields_catalog_variant_bulk_delete_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_category_bulk_update_job | string[]
# $fields_catalog_category | string[]
# $include | string[]

$klaviyo->Catalogs->getUpdateCategoriesJob($job_id, $fields_catalog_category_bulk_update_job=$fields_catalog_category_bulk_update_job, $fields_catalog_category=$fields_catalog_category, $include=$include);
## Keyword Arguments

# $fields_catalog_category_bulk_update_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getUpdateCategoriesJobs($fields_catalog_category_bulk_update_job=$fields_catalog_category_bulk_update_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_item_bulk_update_job | string[]
# $fields_catalog_item | string[]
# $include | string[]

$klaviyo->Catalogs->getUpdateItemsJob($job_id, $fields_catalog_item_bulk_update_job=$fields_catalog_item_bulk_update_job, $fields_catalog_item=$fields_catalog_item, $include=$include);
## Keyword Arguments

# $fields_catalog_item_bulk_update_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getUpdateItemsJobs($fields_catalog_item_bulk_update_job=$fields_catalog_item_bulk_update_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_catalog_variant_bulk_update_job | string[]
# $fields_catalog_variant | string[]
# $include | string[]

$klaviyo->Catalogs->getUpdateVariantsJob($job_id, $fields_catalog_variant_bulk_update_job=$fields_catalog_variant_bulk_update_job, $fields_catalog_variant=$fields_catalog_variant, $include=$include);
## Keyword Arguments

# $fields_catalog_variant_bulk_update_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Catalogs->getUpdateVariantsJobs($fields_catalog_variant_bulk_update_job=$fields_catalog_variant_bulk_update_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnCreateCategoriesJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnCreateItemsJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnCreateVariantsJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnDeleteCategoriesJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnDeleteItemsJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnDeleteVariantsJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnUpdateCategoriesJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnUpdateItemsJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Catalogs->spawnUpdateVariantsJob($body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->updateCatalogCategory($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->updateCatalogCategoryRelationshipsItems($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->updateCatalogItem($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->updateCatalogItemRelationshipsCategories($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Catalogs->updateCatalogVariant($id, $body);

Coupons

## Positional Arguments

# $body | associative array

$klaviyo->Coupons->createCoupon($body);
## Positional Arguments

# $body | associative array

$klaviyo->Coupons->createCouponCode($body);
## Positional Arguments

# $id | string

$klaviyo->Coupons->deleteCoupon($id);
## Positional Arguments

# $id | string

$klaviyo->Coupons->deleteCouponCode($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_coupon | string[]

$klaviyo->Coupons->getCoupon($id, $fields_coupon=$fields_coupon);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_coupon_code | string[]
# $fields_coupon | string[]
# $include | string[]

$klaviyo->Coupons->getCouponCode($id, $fields_coupon_code=$fields_coupon_code, $fields_coupon=$fields_coupon, $include=$include);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_coupon_code_bulk_create_job | string[]
# $fields_coupon_code | string[]
# $include | string[]

$klaviyo->Coupons->getCouponCodeBulkCreateJob($job_id, $fields_coupon_code_bulk_create_job=$fields_coupon_code_bulk_create_job, $fields_coupon_code=$fields_coupon_code, $include=$include);
## Keyword Arguments

# $fields_coupon_code_bulk_create_job | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Coupons->getCouponCodeBulkCreateJobs($fields_coupon_code_bulk_create_job=$fields_coupon_code_bulk_create_job, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $id | string

## Keyword Arguments

# $page_cursor | string

$klaviyo->Coupons->getCouponCodeRelationshipsCoupon($id, $page_cursor=$page_cursor);
## Keyword Arguments

# $fields_coupon_code | string[]
# $fields_coupon | string[]
# $filter | string
# $include | string[]
# $page_cursor | string

$klaviyo->Coupons->getCouponCodes($fields_coupon_code=$fields_coupon_code, $fields_coupon=$fields_coupon, $filter=$filter, $include=$include, $page_cursor=$page_cursor);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_coupon_code | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Coupons->getCouponCodesForCoupon($id, $fields_coupon_code=$fields_coupon_code, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_coupon | string[]

$klaviyo->Coupons->getCouponForCouponCode($id, $fields_coupon=$fields_coupon);
## Positional Arguments

# $id | string

$klaviyo->Coupons->getCouponRelationshipsCouponCodes($id);
## Keyword Arguments

# $fields_coupon | string[]
# $page_cursor | string

$klaviyo->Coupons->getCoupons($fields_coupon=$fields_coupon, $page_cursor=$page_cursor);
## Positional Arguments

# $body | associative array

$klaviyo->Coupons->spawnCouponCodeBulkCreateJob($body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Coupons->updateCoupon($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Coupons->updateCouponCode($id, $body);

DataPrivacy

## Positional Arguments

# $body | associative array

$klaviyo->DataPrivacy->requestProfileDeletion($body);

Events

## Positional Arguments

# $body | associative array

$klaviyo->Events->createEvent($body);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_event | string[]
# $fields_metric | string[]
# $fields_profile | string[]
# $include | string[]

$klaviyo->Events->getEvent($id, $fields_event=$fields_event, $fields_metric=$fields_metric, $fields_profile=$fields_profile, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_metric | string[]

$klaviyo->Events->getEventMetric($id, $fields_metric=$fields_metric);
## Positional Arguments

# $id | string

## Keyword Arguments

# $additional_fields_profile | string[]
# $fields_profile | string[]

$klaviyo->Events->getEventProfile($id, $additional_fields_profile=$additional_fields_profile, $fields_profile=$fields_profile);
## Positional Arguments

# $id | string

$klaviyo->Events->getEventRelationshipsMetric($id);
## Positional Arguments

# $id | string

$klaviyo->Events->getEventRelationshipsProfile($id);
## Keyword Arguments

# $fields_event | string[]
# $fields_metric | string[]
# $fields_profile | string[]
# $filter | string
# $include | string[]
# $page_cursor | string
# $sort | string

$klaviyo->Events->getEvents($fields_event=$fields_event, $fields_metric=$fields_metric, $fields_profile=$fields_profile, $filter=$filter, $include=$include, $page_cursor=$page_cursor, $sort=$sort);

Flows

## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_flow_action | string[]
# $fields_flow | string[]
# $fields_tag | string[]
# $include | string[]

$klaviyo->Flows->getFlow($id, $fields_flow_action=$fields_flow_action, $fields_flow=$fields_flow, $fields_tag=$fields_tag, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_flow_action | string[]
# $fields_flow_message | string[]
# $fields_flow | string[]
# $include | string[]

$klaviyo->Flows->getFlowAction($id, $fields_flow_action=$fields_flow_action, $fields_flow_message=$fields_flow_message, $fields_flow=$fields_flow, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_flow | string[]

$klaviyo->Flows->getFlowActionFlow($id, $fields_flow=$fields_flow);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_flow_message | string[]
# $filter | string
# $page_size | int
# $sort | string

$klaviyo->Flows->getFlowActionMessages($id, $fields_flow_message=$fields_flow_message, $filter=$filter, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

$klaviyo->Flows->getFlowActionRelationshipsFlow($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Flows->getFlowActionRelationshipsMessages($id, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_flow_action | string[]
# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Flows->getFlowFlowActions($id, $fields_flow_action=$fields_flow_action, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_flow_action | string[]
# $fields_flow_message | string[]
# $fields_template | string[]
# $include | string[]

$klaviyo->Flows->getFlowMessage($id, $fields_flow_action=$fields_flow_action, $fields_flow_message=$fields_flow_message, $fields_template=$fields_template, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_flow_action | string[]

$klaviyo->Flows->getFlowMessageAction($id, $fields_flow_action=$fields_flow_action);
## Positional Arguments

# $id | string

$klaviyo->Flows->getFlowMessageRelationshipsAction($id);
## Positional Arguments

# $id | string

$klaviyo->Flows->getFlowMessageRelationshipsTemplate($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_template | string[]

$klaviyo->Flows->getFlowMessageTemplate($id, $fields_template=$fields_template);
## Positional Arguments

# $id | string

## Keyword Arguments

# $filter | string
# $page_size | int
# $sort | string

$klaviyo->Flows->getFlowRelationshipsFlowActions($id, $filter=$filter, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

$klaviyo->Flows->getFlowRelationshipsTags($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_tag | string[]

$klaviyo->Flows->getFlowTags($id, $fields_tag=$fields_tag);
## Keyword Arguments

# $fields_flow_action | string[]
# $fields_flow | string[]
# $fields_tag | string[]
# $filter | string
# $include | string[]
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Flows->getFlows($fields_flow_action=$fields_flow_action, $fields_flow=$fields_flow, $fields_tag=$fields_tag, $filter=$filter, $include=$include, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Flows->updateFlow($id, $body);

Images

## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_image | string[]

$klaviyo->Images->getImage($id, $fields_image=$fields_image);
## Keyword Arguments

# $fields_image | string[]
# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Images->getImages($fields_image=$fields_image, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Images->updateImage($id, $body);
## Positional Arguments

# $file | \SplFileObject

## Keyword Arguments

# $name | string
# $hidden | bool

$klaviyo->Images->uploadImageFromFile($file, $name=$name, $hidden=$hidden);
## Positional Arguments

# $body | associative array

$klaviyo->Images->uploadImageFromUrl($body);

Lists

## Positional Arguments

# $body | associative array

$klaviyo->Lists->createList($body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Lists->createListRelationships($id, $body);
## Positional Arguments

# $id | string

$klaviyo->Lists->deleteList($id);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Lists->deleteListRelationships($id, $body);
## Positional Arguments

# $id | string

## Keyword Arguments

# $additional_fields_list | string[]
# $fields_list | string[]
# $fields_tag | string[]
# $include | string[]

$klaviyo->Lists->getList($id, $additional_fields_list=$additional_fields_list, $fields_list=$fields_list, $fields_tag=$fields_tag, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $additional_fields_profile | string[]
# $fields_profile | string[]
# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Lists->getListProfiles($id, $additional_fields_profile=$additional_fields_profile, $fields_profile=$fields_profile, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Lists->getListRelationshipsProfiles($id, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

$klaviyo->Lists->getListRelationshipsTags($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_tag | string[]

$klaviyo->Lists->getListTags($id, $fields_tag=$fields_tag);
## Keyword Arguments

# $fields_list | string[]
# $fields_tag | string[]
# $filter | string
# $include | string[]
# $page_cursor | string

$klaviyo->Lists->getLists($fields_list=$fields_list, $fields_tag=$fields_tag, $filter=$filter, $include=$include, $page_cursor=$page_cursor);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Lists->updateList($id, $body);

Metrics

## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_metric | string[]

$klaviyo->Metrics->getMetric($id, $fields_metric=$fields_metric);
## Keyword Arguments

# $fields_metric | string[]
# $filter | string
# $page_cursor | string

$klaviyo->Metrics->getMetrics($fields_metric=$fields_metric, $filter=$filter, $page_cursor=$page_cursor);
## Positional Arguments

# $body | associative array

$klaviyo->Metrics->queryMetricAggregates($body);

Profiles

## Positional Arguments

# $body | associative array

$klaviyo->Profiles->createOrUpdateProfile($body);
## Positional Arguments

# $body | associative array

$klaviyo->Profiles->createProfile($body);
## Positional Arguments

# $body | associative array

$klaviyo->Profiles->createPushToken($body);
## Positional Arguments

# $job_id | string

## Keyword Arguments

# $fields_list | string[]
# $fields_profile_bulk_import_job | string[]
# $include | string[]

$klaviyo->Profiles->getBulkProfileImportJob($job_id, $fields_list=$fields_list, $fields_profile_bulk_import_job=$fields_profile_bulk_import_job, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_import_error | string[]
# $page_cursor | string
# $page_size | int

$klaviyo->Profiles->getBulkProfileImportJobImportErrors($id, $fields_import_error=$fields_import_error, $page_cursor=$page_cursor, $page_size=$page_size);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_list | string[]

$klaviyo->Profiles->getBulkProfileImportJobLists($id, $fields_list=$fields_list);
## Positional Arguments

# $id | string

## Keyword Arguments

# $additional_fields_profile | string[]
# $fields_profile | string[]
# $page_cursor | string
# $page_size | int

$klaviyo->Profiles->getBulkProfileImportJobProfiles($id, $additional_fields_profile=$additional_fields_profile, $fields_profile=$fields_profile, $page_cursor=$page_cursor, $page_size=$page_size);
## Positional Arguments

# $id | string

$klaviyo->Profiles->getBulkProfileImportJobRelationshipsLists($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $page_cursor | string
# $page_size | int

$klaviyo->Profiles->getBulkProfileImportJobRelationshipsProfiles($id, $page_cursor=$page_cursor, $page_size=$page_size);
## Keyword Arguments

# $fields_profile_bulk_import_job | string[]
# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Profiles->getBulkProfileImportJobs($fields_profile_bulk_import_job=$fields_profile_bulk_import_job, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $additional_fields_profile | string[]
# $fields_list | string[]
# $fields_profile | string[]
# $fields_segment | string[]
# $include | string[]

$klaviyo->Profiles->getProfile($id, $additional_fields_profile=$additional_fields_profile, $fields_list=$fields_list, $fields_profile=$fields_profile, $fields_segment=$fields_segment, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_list | string[]

$klaviyo->Profiles->getProfileLists($id, $fields_list=$fields_list);
## Positional Arguments

# $id | string

$klaviyo->Profiles->getProfileRelationshipsLists($id);
## Positional Arguments

# $id | string

$klaviyo->Profiles->getProfileRelationshipsSegments($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_segment | string[]

$klaviyo->Profiles->getProfileSegments($id, $fields_segment=$fields_segment);
## Keyword Arguments

# $additional_fields_profile | string[]
# $fields_profile | string[]
# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Profiles->getProfiles($additional_fields_profile=$additional_fields_profile, $fields_profile=$fields_profile, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $body | associative array

$klaviyo->Profiles->mergeProfiles($body);
## Positional Arguments

# $body | associative array

$klaviyo->Profiles->spawnBulkProfileImportJob($body);
## Positional Arguments

# $body | associative array

$klaviyo->Profiles->subscribeProfiles($body);
## Positional Arguments

# $body | associative array

$klaviyo->Profiles->suppressProfiles($body);
## Positional Arguments

# $body | associative array

$klaviyo->Profiles->unsubscribeProfiles($body);
## Positional Arguments

# $body | associative array

$klaviyo->Profiles->unsuppressProfiles($body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Profiles->updateProfile($id, $body);

Reporting

## Positional Arguments

# $body | associative array

## Keyword Arguments

# $page_cursor | string

$klaviyo->Reporting->queryCampaignValues($body, $page_cursor=$page_cursor);
## Positional Arguments

# $body | associative array

## Keyword Arguments

# $page_cursor | string

$klaviyo->Reporting->queryFlowSeries($body, $page_cursor=$page_cursor);
## Positional Arguments

# $body | associative array

## Keyword Arguments

# $page_cursor | string

$klaviyo->Reporting->queryFlowValues($body, $page_cursor=$page_cursor);

Segments

## Positional Arguments

# $id | string

## Keyword Arguments

# $additional_fields_segment | string[]
# $fields_segment | string[]
# $fields_tag | string[]
# $include | string[]

$klaviyo->Segments->getSegment($id, $additional_fields_segment=$additional_fields_segment, $fields_segment=$fields_segment, $fields_tag=$fields_tag, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $additional_fields_profile | string[]
# $fields_profile | string[]
# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Segments->getSegmentProfiles($id, $additional_fields_profile=$additional_fields_profile, $fields_profile=$fields_profile, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

## Keyword Arguments

# $filter | string
# $page_cursor | string
# $page_size | int
# $sort | string

$klaviyo->Segments->getSegmentRelationshipsProfiles($id, $filter=$filter, $page_cursor=$page_cursor, $page_size=$page_size, $sort=$sort);
## Positional Arguments

# $id | string

$klaviyo->Segments->getSegmentRelationshipsTags($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_tag | string[]

$klaviyo->Segments->getSegmentTags($id, $fields_tag=$fields_tag);
## Keyword Arguments

# $fields_segment | string[]
# $fields_tag | string[]
# $filter | string
# $include | string[]
# $page_cursor | string

$klaviyo->Segments->getSegments($fields_segment=$fields_segment, $fields_tag=$fields_tag, $filter=$filter, $include=$include, $page_cursor=$page_cursor);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Segments->updateSegment($id, $body);

Tags

## Positional Arguments

# $body | associative array

$klaviyo->Tags->createTag($body);
## Positional Arguments

# $body | associative array

$klaviyo->Tags->createTagGroup($body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->createTagRelationshipsCampaigns($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->createTagRelationshipsFlows($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->createTagRelationshipsLists($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->createTagRelationshipsSegments($id, $body);
## Positional Arguments

# $id | string

$klaviyo->Tags->deleteTag($id);
## Positional Arguments

# $id | string

$klaviyo->Tags->deleteTagGroup($id);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->deleteTagRelationshipsCampaigns($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->deleteTagRelationshipsFlows($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->deleteTagRelationshipsLists($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->deleteTagRelationshipsSegments($id, $body);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_tag_group | string[]
# $fields_tag | string[]
# $include | string[]

$klaviyo->Tags->getTag($id, $fields_tag_group=$fields_tag_group, $fields_tag=$fields_tag, $include=$include);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_tag_group | string[]

$klaviyo->Tags->getTagGroup($id, $fields_tag_group=$fields_tag_group);
## Positional Arguments

# $id | string

$klaviyo->Tags->getTagGroupRelationshipsTags($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_tag | string[]

$klaviyo->Tags->getTagGroupTags($id, $fields_tag=$fields_tag);
## 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);
## Positional Arguments

# $id | string

$klaviyo->Tags->getTagRelationshipsCampaigns($id);
## Positional Arguments

# $id | string

$klaviyo->Tags->getTagRelationshipsFlows($id);
## Positional Arguments

# $id | string

$klaviyo->Tags->getTagRelationshipsLists($id);
## Positional Arguments

# $id | string

$klaviyo->Tags->getTagRelationshipsSegments($id);
## Positional Arguments

# $id | string

$klaviyo->Tags->getTagRelationshipsTagGroup($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_tag_group | string[]

$klaviyo->Tags->getTagTagGroup($id, $fields_tag_group=$fields_tag_group);
## 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);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->updateTag($id, $body);
## Positional Arguments

# $id | string
# $body | associative array

$klaviyo->Tags->updateTagGroup($id, $body);

Templates

## Positional Arguments

# $body | associative array

$klaviyo->Templates->createTemplate($body);
## Positional Arguments

# $body | associative array

$klaviyo->Templates->createTemplateClone($body);
## Positional Arguments

# $body | associative array

$klaviyo->Templates->createTemplateRender($body);
## Positional Arguments

# $id | string

$klaviyo->Templates->deleteTemplate($id);
## Positional Arguments

# $id | string

## Keyword Arguments

# $fields_template | string[]

$klaviyo->Templates->getTemplate($id, $fields_template=$fields_template);
## 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);
## 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-level api_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

  1. All parameters are passed as function args.
  2. All optional params, as well as all Body and Form Data params (including required ones), are passed as keyword args.
  3. All query and path params that are tagged as required in the docs are passed as positional args.
  4. $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.

klaviyo-api-php's People

Contributors

aimalamiri avatar dano-klaviyo avatar jon-batscha avatar klaviyo-sdk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

klaviyo-api-php's Issues

Error while creating a profile

Hi! I'm trying to use this SDK, following the documentation I have an error when trying to create a profile.

This is my code

 `$klaviyo = new KlaviyoClient(
        $api_key = $this->config['private_api_key'],
    );
    try {
        $klaviyo->Profiles->createProfile(json_encode($body));
    } catch (Exception $exception) {
        echo $exception;
    }`

This is the error I got
KlaviyoAPI\ApiException [400] Client error: POST https://a.klaviyo.com/api/profiles/ resulted in a 400 Bad Request response: {"errors":[{"id":"a9080d30-8e7c-446e-b384-...","status":400,"code":"invalid","title":"Invalid input.","detail": (truncated...).

While debugging on ProfileApi.php I dd $profile and $apikey to see what was wrong but I found that the key is null despite I'm passing it, I also tried instead of $this->config['private_api_key'] passing the real key.

public function createProfileWithHttpInfo($profile_create_query, $apiKey = null) { dd("here", $apiKey, $profile_create_query);

I think this could be a bug, I found another person with the same issue. If not I really appreciate your help.

$consent variable reseted after double opt-in subscription?

Upgrading from Klaviyo's PHP v1.2 API to v5.1. At our webstore we have page for marketing consents where user can select Klaviyo's global $consent variable values: email, web, sms, directmail and mobile. Looks like these are now saved under Klaviyo's Profile['attributes']['properties']['$consent'] and are there after save (Profile -> Patch).

Now if all these consents are selected and user only unsubscribes from the email through web store - like newsletter (API: profile-subscription-bulk-delete-jobs) - and then later resubscribes back using double-opt-in (API: profile-subscription-bulk-create-job), $consent variable looses all values but email and/or sms depending on if phone number was set.

Is this normal behaviour? Or I'm missing some variables?

Basic plugin analysis failed.

I updated to the latest version 7.1 and Shopware Plugin analysis failed, because of constant names are used twice:

Fatal error: Cannot redefine class constant KlaviyoAPI\Model\MetricAggregateQueryResourceObjectAttributes::SORT_BOUNCE_TYPE in //vendor/klaviyo/api/lib/Model/MetricAggregateQueryResourceObjectAttributes.php on line 336

Errors parsing /vendor/klaviyo/api/lib/Model/MetricAggregateQueryResourceObjectAttributes.php

public const SORT_BOUNCE_TYPE = 'Bounce Type';
public const SORT_BOUNCE_TYPE = '-Bounce Type';

I already raised this issue several versions before last year, and it was fixed: #19
But now it looks like its back in. :)

Undefined array key 3 on getProfiles endpoint when using more than 3 arguments

I have the following line of code

$response = $this->klaviyoAPI->Profiles->getProfiles(filter: $filter, apiKey: config('klaviyo.api_token'), page_cursor: $pageCursor, page_size: $pageSize);

This give me the following error

   ErrorException 

  Undefined array key 3

  at vendor/klaviyo/api/lib/Subclient.php:47
     43▕             $param_position = $param->getPosition();
     44▕ 
     45▕             if (count($args) > $param_position) {
     46▕ 
  ➜  47▕                 $page_cursor = $args[$param_position];
     48▕                 if ($page_cursor != NULL) {
     49▕                     $page_cursor = $this->new_page_cursor($page_cursor);
     50▕ 
     51▕                     $args[$param_position] = $page_cursor;

If I reduce the amount of arguments to 3, it works correctly. Also, by stepping through the code above, I notice that the $args array in line 47 does indeed not have numbered keys, but named keys, which is why it fails.

Add unit tests and code coverage checks.

While reviewing a ticket, I was curious to see what types of test cases were covered based on the existing logic. In doing so, I noticed that there aren't any tests associated to the existing code. Is this repository being autogenerated in a way that is being tested outside this codebase? I think adding tests would be very valuable.

page_cursor not working or documented wrong

According to the documentation, the parameter page_cursor in getProfiles() is supposed to be the content of the "next" attribute. Doing so will parse the entire URL into the url parameter, page_cursor.

So either it's not working as intended or the documentation is incorrect

Use PSR-18 "http-client" interface instead of Guzzle

This project is using Guzzle as its HTTP client. Nowadays most projects (including frameworks) already have a PSR-18 compatible HTTP client library. It's been like that for some time and there are options to choose from if you want to use something different.

It will be a lot better if the selection of the HTTP client to use is left to the developer. You will remove the hard dependency to Guzzle, and make it easier to add test coverage for this project.

You can still recommend Guzzle and its adapters in composer.json as your preferred suggestion. You can also add some very quick detection of known "http-client" projects to make it easier to use with less configuration.

Create a new profile using php sdk not working

  1. Can we find profile with custom filter in the klaviyo site and send bulk email? Example: find those profiles whose plan is expired or who's renewed the plan.

  2. I have connected klaviyo php sdk with codeigniter successfully. I have getting the profile data by id. But when I add new profile with SDK example, I'm not facing an error on my site but no data added in profile lists using this approach.
    Can you help me to resolve this issue?

<?php
use KlaviyoAPI\KlaviyoAPI;
$klaviyoAPI = new KlaviyoAPI( KALVIYO_PRIVATE_KEY );
$klaviyoAPI->Profiles->createProfile([
                "data" => [
                    "type" => "profile",
                    "attributes" => [
                        'email' => '[email protected]',
                        'first_name' => 'John',
                        'last_name' => 'Doe',
                        'phone_number' => '004300005400',
                        "external_id"=>"63f64a2b-c6bf-40c7-b81f-bed08162edbe",
                        'organization' => 'Example Corporation',
                        'title' => 'Regional Manager',
                        'image' => '',
                        'location' => [
                            "address1"=>"Test",
                            "address2"=>"Test1",
                            "city"=>"New York",
                            "country"=>"United States",
                            "region"=>"NY",
                            "zip"=>"00000",
                            "timezone"=>"America/New_York",
                            "ip"=>"127.0.0.1"
                        ],
                        'properties' => [],
                    ],
                ],
            ]);

Url: https://github.com/klaviyo/klaviyo-api-php
image
image

Creation of dynamic property is deprecated at PHP 8.1 and above

Hi!

PHP-Version > 8.1.0
Klaviyo SDK 1.0.1

Code to reproduce:

$klaviyo = new KlaviyoAPI(
    'YOUR_KEY',
    $num_entries = 3,
    $wait_seconds = 3
);

/**
 * @type MetricsApi $metrics
 */
$metrics = $klaviyo->Metrics;

try {
    $response = $metrics->getMetrics();
    echo json_encode($response);
} catch (ApiException $e) {
    echo $e->getCode() . ' ' . $e->getMessage();
}

Results in:

Deprecated: Creation of dynamic property KlaviyoAPI\KlaviyoAPI::$config is deprecated in /vendor/klaviyo/api/lib/KlaviyoAPI.php on line 51

Deprecated: Creation of dynamic property KlaviyoAPI\Subclient::$api_instance is deprecated in /vendor/klaviyo/api/lib/Subclient.php on line 12

Deprecated: Creation of dynamic property KlaviyoAPI\Subclient::$wait_seconds is deprecated in /vendor/klaviyo/api/lib/Subclient.php on line 13

Deprecated: Creation of dynamic property KlaviyoAPI\Subclient::$num_retries is deprecated in /vendor/klaviyo/api/lib/Subclient.php on line 14

Deprecated: Creation of dynamic property KlaviyoAPI\Subclient::$retry_codes is deprecated in /vendor/klaviyo/api/lib/Subclient.php on line 15

... and so on

See https://wiki.php.net/rfc/deprecate_dynamic_properties for more information.

Best Regards

Undefined property: KlaviyoAPI\KlaviyoAPI::$3

      $this->Campaigns = new Subclient(
              new CampaignsApi(new GuzzleClient($this->guzzle_options),$this->config),
              $wait_seconds = $this->$wait_seconds,
              $num_retries = $this->$num_retries,
          );

"Extra '$' symbol when accessing wait_seconds and num_retries properties."

$body payload structure

Hi - hope someone can help. I suspect I'm making a fairly basic error.

I'm attempting to use the klaviyo-api-php library to add subscribers and update profiles.

I've already successfully used the php library to retrieve info on profiles i.e. using $klaviyo->Lists->getListProfiles($list_id, $fields_profile, $filter);

However I'm now really stuck when trying to subscribe a profile to list.

Error message returned is:
"status":400,"code":"invalid","title":"Invalid input.","detail":"The payload provided in the request is invalid.","source":{"pointer":"/data"},"meta":{}}]}

I can't figure out how to structure the data in the request $body.
I know it needs to be an associative array and have tried various options, but everything I try fails.

Below is my $body payload. (list_id removed)
I'd be really grateful if anyone could help me structure or format it correctly. I can't see where I'm going wrong!

Many thanks


$body = array(
  'list_id' => 'LIST_ID',
  'profiles' => array(
    array(
      'email' => '[email protected]',
      'properties' => array(
        '$first_name' => 'John',
        '$last_name' => 'Doe',
      ),
    ),
  ),
);

$klaviyo->Profiles->subscribeProfiles($body);

GitHub docs:

## Positional Arguments

# $body | associative array

$klaviyo->Profiles->subscribeProfiles($body);

Klaviyo API docs:
https://developers.klaviyo.com/en/v2022-10-17/reference/subscribe_profiles

Can't mock Guzzle?

Hi,

Just trying to update our system to use this new PHP Client, however it doesn't look like it's built to be compatible with mocked http clients for testing?

E.g. when spinning up an instance of Guzzle, you're meant to be able to pass in a handler which can be mocked, e.g. these from the docs:

// Create a mock and queue two responses.
$mock = new MockHandler([
    new Response(200, ['X-Foo' => 'Bar'], 'Hello, World'),
    new Response(202, ['Content-Length' => 0]),
    new RequestException('Error Communicating with Server', new Request('GET', 'test'))
]);

$handlerStack = HandlerStack::create($mock);
$client = new Client(['handler' => $handlerStack]);

However when you look at the code of the new KlaviyoAPI class, it just spins up the client without allowing a handler to be passed in.

e.g.

$this->Catalogs = new Subclient(
        new CatalogsApi(new GuzzleClient(),$this->config),
        $wait_seconds = 3,
        $num_retries = 3,
    );

$this->Client = new Subclient(
        new ClientApi(new GuzzleClient(),$this->config),
        $wait_seconds = 3,
        $num_retries = 3,
    );

This could be potentially fixed by allowing guzzle options to be passed in via the construct e.g.

public function __construct($api_key, $num_retries = 3, $wait_seconds = 3, $guzzle_options = []) {

Then when you instantiate the clients, you pass it in.

$this->Catalogs = new Subclient(
            new CatalogsApi(new GuzzleClient($guzzle_options),$this->config),
            $wait_seconds = 3,
            $num_retries = 3,
        );

Please advise...

Thanks

Constant names assigned twice

In file klaviyo/api/lib/Model/MetricAggregateQueryResourceObjectAttributes.php are several constant assigned twice.

public const SORT_BOUNCE_TYPE = 'Bounce Type';
public const SORT_BOUNCE_TYPE = '-Bounce Type';
public const SORT_CAMPAIGN_NAME = 'Campaign Name';
public const SORT_CAMPAIGN_NAME = '-Campaign Name';
public const SORT_CLIENT_CANONICAL = 'Client Canonical';
public const SORT_CLIENT_CANONICAL = '-Client Canonical';
public const SORT_CLIENT_NAME = 'Client Name';
public const SORT_CLIENT_NAME = '-Client Name';
public const SORT_CLIENT_TYPE = 'Client Type';
public const SORT_CLIENT_TYPE = '-Client Type';
public const SORT_EMAIL_DOMAIN = 'Email Domain';
public const SORT_EMAIL_DOMAIN = '-Email Domain';
public const SORT_FAILURE_SOURCE = 'Failure Source';
public const SORT_FAILURE_SOURCE = '-Failure Source';
public const SORT_FAILURE_TYPE = 'Failure Type';
public const SORT_FAILURE_TYPE = '-Failure Type';
public const SORT_FROM_NUMBER = 'From Number';
public const SORT_FROM_NUMBER = '-From Number';
public const SORT_FROM_PHONE_REGION = 'From Phone Region';
public const SORT_FROM_PHONE_REGION = '-From Phone Region';
public const SORT__LIST = 'List';
public const SORT__LIST = '-List';
public const SORT_MESSAGE_NAME = 'Message Name';
public const SORT_MESSAGE_NAME = '-Message Name';
public const SORT_MESSAGE_TYPE = 'Message Type';
public const SORT_MESSAGE_TYPE = '-Message Type';
public const SORT_METHOD = 'Method';
public const SORT_METHOD = '-Method';
public const SORT_SUBJECT = 'Subject';
public const SORT_SUBJECT = '-Subject';
public const SORT_TO_NUMBER = 'To Number';
public const SORT_TO_NUMBER = '-To Number';
public const SORT_TO_PHONE_REGION = 'To Phone Region';
public const SORT_TO_PHONE_REGION = '-To Phone Region';
public const SORT_URL = 'URL';
public const SORT_URL = '-URL';
public const SORT_COUNT = 'count';
public const SORT_COUNT = '-count';
public const SORT_FORM_ID = 'form_id';
public const SORT_FORM_ID = '-form_id';
public const SORT_SUM_VALUE = 'sum_value';
public const SORT_SUM_VALUE = '-sum_value';
public const SORT_UNIQUE = 'unique';
public const SORT_UNIQUE = '-unique';

Whats the background for this?

How we able to use sendEvent?

I am wondering why there is no example how to use this sdk?
What approach should I use to be successful with this sdk?

For example here is my code

public function sendEvent( $event_name, $customer_email, $customer_properties = array(), $properties = array() ) {
        $eventData = [
            'data' => [
                'type' => 'event',
                'attributes' => [
                    'event' => $event_name,
                    'profile' => ['$email' => $customer_email] + $customer_properties,
                    'properties' => $properties,
                ],
            ],
        ];
        
        $event = new KlaviyoAPI\Model\EventCreateQueryV2( $eventData );  
        $resp = $this->client->Events->createEvent($event);
}

to use createEvent i need to first create an object of event via some weird EventCreateQueryV2 but there is no example of data structure... How can i do it?

Can't install on Laravel6

I’m trying to integrate klaviyo/api on my laravel 6 application but it show an error for like this. I can’t upgrate the guzzle because it satisfied by other package.

image

Array to String Conversion - createListsRelationships()

Experiencing an Array to String Conversion error when using the createListsRelationships method of the List API.

The controller code that is leading to the error looks like this:

$subscriber_add_body = ['data'=>['type'=>'profile','id'=>$subscriber_id]];
$klaviyo->Lists->createListRelationships($_ENV['KLAVIYO_LIST_ID'], 'profiles', $subscriber_add_body);

($subscriber_id is a string)
(The Klaviyo List Id ENV var is a string)

Perhaps I'm formatting the body incorrectly however this code used to work for us, but no longer does. I'm not sure when it began to fail unfortunately, perhaps after an update, but I was just made aware of it.

The error is as follows:

[DefaultController.php](_profiler/open?file=src/Controller/DefaultController.php&line=541#line541) on line 541:
ErrorException {#2710 ▼
  #message: "Warning: Array to string conversion"
  #code: 0
  #file: "[/vendor/klaviyo/api/lib/API/ListsApi.php](_profiler/open?file=vendor/klaviyo/api/lib/API/ListsApi.php&line=724#line724)"
  #line: 724
  #severity: E_WARNING
  }
}

Errors in using updateProfile and createProfile

I'm attempting to update a profile using the user's profile id.
Example:

$klaviyo_api = new KlaviyoAPI(
    "MyKlaviyoApiKey", 
    $num_retries = 3, 
    $wait_seconds = 3
);
                            
try {
    $klaviyo_api->Profiles->updateProfile(
        "xxxxxxxxxxxxxxxxxx", // here we would place the profile id from Klaviyo
       [
            'email' => "[email protected]",
            'first_name' => "Some",
            'last_name' => "User",
            'properties' => [
                'MyCustomProperty' => 1
            ]
       ]
    );
} catch (Exception $e) {
    print_r($e->getMessage());
}

But I'm getting this:

[400] Client error: `PATCH https://a.klaviyo.com/api/profiles/01HMKGK1BB4D6VV4ZNGJRBKQMS/` resulted in a `400 Bad Request` response:
{"errors":[{"id":"67ac7dee-5f10-4e1c-9a3a-2abf14a93cc6","status":400,"code":"invalid","title":"Invalid input.","detail": (truncated...)

Of course it is ALWAYS truncated so I can't even debug this thing. What am I doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.