定制 jmarcone/klaviyo-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jmarcone/klaviyo-sdk

Composer 安装命令:

composer require jmarcone/klaviyo-sdk

包简介

Empowering creators to own their destiny

README 文档

README

  • SDK version: 1.0.1.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.

optional 1a: with composer installed

If you have composer installed, you can run: composer require klaviyo/sdk

optional 1b: without composer installed

If you don't have composer installed, you can get an executable version by running bash composer.sh

This will download an executable version of composer that you can use by running php composer.phar wherever you would otherwise run composer.

You can then install the library from Packagist by running php composer.phar require klaviyo/sdk

Option 2: Source code

You can also install this library directly from source code, without using the Packagist package, as follows:

  1. cloning this repo
  2. running bash composer.json

Usage Example

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

use Klaviyo\Client;

$client = new Client(
    'YOUR_API_KEY', 
    $num_retries = 3, 
    $wait_seconds = 3);

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

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:

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

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 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.

Campaigns

Cancel a Campaign

## Positional Arguments

# $campaign_id | string


client->Campaigns->cancelCampaign($campaign_id);

Clone a Campaign

## Positional Arguments

# $campaign_id | string
# $name | string
# $list_id | string


client->Campaigns->cloneCampaign($campaign_id, $name, $list_id);

Create New Campaign

## Positional Arguments

# $list_id | string
# $template_id | string
# $from_email | string
# $from_name | string
# $subject | string

## Keyword Arguments

# $name | string
# $use_smart_sending | bool
# $add_google_analytics | bool

client->Campaigns->createCampaign($list_id, $template_id, $from_email, $from_name, $subject);

Get Campaign Info

## Positional Arguments

# $campaign_id | string


client->Campaigns->getCampaignInfo($campaign_id);

Get Campaign Recipients

## Positional Arguments

# $campaign_id | string

## Keyword Arguments

# $count | int
# $sort | string
# $offset | string

client->Campaigns->getCampaignRecipients($campaign_id);

Get Campaigns

## Keyword Arguments

# $page | int
# $count | int

client->Campaigns->getCampaigns();

Schedule a Campaign

## Positional Arguments

# $campaign_id | string
# $send_time | string


client->Campaigns->scheduleCampaign($campaign_id, $send_time);

Send a Campaign Immediately

## Positional Arguments

# $campaign_id | string


client->Campaigns->sendCampaign($campaign_id);

Update Campaign

## Positional Arguments

# $campaign_id | string

## Keyword Arguments

# $list_id | string
# $template_id | string
# $from_email | string
# $from_name | string
# $subject | string
# $name | string
# $use_smart_sending | bool
# $add_google_analytics | bool

client->Campaigns->updateCampaign($campaign_id);

DataPrivacy

Request a Deletion

## Keyword Arguments

# $body | array

client->DataPrivacy->requestDeletion();

ListsSegments

Add Members to a List

## Positional Arguments

# $list_id | string

## Keyword Arguments

# $body | array

client->ListsSegments->addMembers($list_id);

Create List

## Positional Arguments

# $list_name | string


client->ListsSegments->createList($list_name);

Delete List

## Positional Arguments

# $list_id | string


client->ListsSegments->deleteList($list_id);

Exclude Profile From All Email

## Positional Arguments

# $email | string


client->ListsSegments->excludeGlobally($email);

Get Global Exclusions & Unsubscribes

## Keyword Arguments

# $reason | string
# $sort | string
# $count | int
# $page | int

client->ListsSegments->getGlobalExclusions();

Get All Exclusions for a List

## Positional Arguments

# $list_id | string

## Keyword Arguments

# $marker | int

client->ListsSegments->getListExclusions($list_id);

Get List Info

## Positional Arguments

# $list_id | string


client->ListsSegments->getListInfo($list_id);

Check if Profiles Are in a List

## Positional Arguments

# $list_id | string

## Keyword Arguments

# $body | array

client->ListsSegments->getListMembers($list_id);

Check if Profiles Are in a List and not Suppressed

## Positional Arguments

# $list_id | string

## Keyword Arguments

# $body | array

client->ListsSegments->getListSubscriptions($list_id);

Get Lists

client->ListsSegments->getLists();

Get List and Segment Members

## Positional Arguments

# $list_or_segment_id | string

## Keyword Arguments

# $marker | int

client->ListsSegments->getMembers($list_or_segment_id);

Check if Profiles Are in a Segment

## Positional Arguments

# $segment_id | string

## Keyword Arguments

# $body | array

client->ListsSegments->getSegmentMembers($segment_id);

Remove Profiles From List

## Positional Arguments

# $list_id | string

## Keyword Arguments

# $body | array

client->ListsSegments->removeMembers($list_id);

Subscribe Profiles to List

## Positional Arguments

# $list_id | string

## Keyword Arguments

# $body | array

client->ListsSegments->subscribe($list_id);

Unsubscribe Profiles From List

## Positional Arguments

# $list_id | string

## Keyword Arguments

# $body | array

client->ListsSegments->unsubscribe($list_id);

Update List Name

## Positional Arguments

# $list_id | string
# $list_name | string


client->ListsSegments->updateListName($list_id, $list_name);

Metrics

Get Metrics Info

## Keyword Arguments

# $page | int
# $count | int

client->Metrics->getMetrics();

Query Event Data

## Positional Arguments

# $metric_id | string

## Keyword Arguments

# $start_date | string
# $end_date | string
# $unit | string
# $measurement | string
# $where | string
# $by | string
# $count | int

client->Metrics->metricExport($metric_id);

Get Events for a Specific Metric

## Positional Arguments

# $metric_id | string

## Keyword Arguments

# $since | string
# $count | int
# $sort | string

client->Metrics->metricTimeline($metric_id);

Get Events for All Metrics

## Keyword Arguments

# $since | string
# $count | int
# $sort | string

client->Metrics->metricsTimeline();

Profiles

Exchange ID for Profile ID

## Keyword Arguments

# $body | array

client->Profiles->exchange();

Get Profile

## Positional Arguments

# $person_id | string


client->Profiles->getProfile($person_id);

Get Profile's Events for a Specific Metric

## Positional Arguments

# $person_id | string
# $metric_id | string

## Keyword Arguments

# $since | string
# $count | int
# $sort | string

client->Profiles->profileMetricTimeline($person_id, $metric_id);

Get Profile's Events for all Metrics

## Positional Arguments

# $person_id | string

## Keyword Arguments

# $since | string
# $count | int
# $sort | string

client->Profiles->profileMetricsTimeline($person_id);

Update Profile

## Positional Arguments

# $person_id | string

## Keyword Arguments

# $params | array&lt;string,object&gt;

client->Profiles->updateProfile($person_id);

Templates

Clone Template

## Positional Arguments

# $template_id | string
# $name | string


client->Templates->cloneTemplate($template_id, $name);

Create New Template

## Positional Arguments

# $name | string
# $html | string


client->Templates->createTemplate($name, $html);

Delete Template

## Positional Arguments

# $template_id | string


client->Templates->deleteTemplate($template_id);

Get All Templates

## Keyword Arguments

# $page | int
# $count | int

client->Templates->getTemplates();

Render Template

## Positional Arguments

# $template_id | string

## Keyword Arguments

# $context | string

client->Templates->renderTemplate($template_id);

Render and Send Template

## Positional Arguments

# $template_id | string
# $from_email | string
# $from_name | string
# $subject | string
# $to | string

## Keyword Arguments

# $context | string

client->Templates->sendTemplate($template_id, $from_email, $from_name, $subject, $to);

Update Template

## Positional Arguments

# $template_id | string

## Keyword Arguments

# $name | string
# $html | string

client->Templates->updateTemplate($template_id);

TrackIdentify

Identify Profile (Legacy)

## Positional Arguments

# $data | string


client->TrackIdentify->identifyGet($data);

Identify Profile

## Positional Arguments

# $data | string


client->TrackIdentify->identifyPost($data);

Track Profile Activity (Legacy)

## Positional Arguments

# $data | string


client->TrackIdentify->trackGet($data);

Track Profile Activity

## Positional Arguments

# $data | string


client->TrackIdentify->trackPost($data);

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 becomes TrackIdentify
  • get-campaigns becomes getCampaigns
  • 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

  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. 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.

jmarcone/klaviyo-sdk 适用场景与选型建议

jmarcone/klaviyo-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「rest」 「api」 「email」 「sms」 「sdk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jmarcone/klaviyo-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jmarcone/klaviyo-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 jmarcone/klaviyo-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-02