根据campaign monitor的示例代码,在添加新订阅者
时,可以像这样传递自定义字段的值<?php
require_once '../../csrest_subscribers.php';
$wrap = new CS_REST_Subscribers('Your list ID', 'Your API Key');
$result = $wrap->add(array(
'EmailAddress' => 'Subscriber email',
'Name' => 'Subscriber name',
'CustomFields' => array(
array(
'Key' => 'Field Key',
'Value' => 'Field Value'
)
),
'Resubscribe' => true
));
?>
现在上面的代码工作良好,如果我传递一个值到CustomFields元素,但不工作,当我试图传递多个值。我已经搜索了API文档,但无法找到有关如何将多个值传递到单个自定义字段键的任何信息。
我想要做的是沿着这一行
'CustomFields' => array(
array(
'Key' => 'Field Key',
'Value' => 'Value 1, Value2'
//OR 'Value' => array('value1', 'value2')
)
),
请注意我是如何使用逗号作为分隔符传递两个值的。请有人知道如何做我想要实现或知道这是否支持竞选监控API或不。如能提供任何相关信息,我将不胜感激。
谢谢
这个代码是为我工作。您需要在您的项目文件夹中添加活动监视器类文件,并使用有效的列表id和api密钥。您可以从管理帐户链接和列表id中找到您的api密钥,单击(更改名称/类型)下面的列表标题。
您需要从listid创建"自定义字段"(在右侧栏)。Ex(主题、电话号码、郊区、留言等)
当导出订阅者列表时,可以找到自定义的归档数据。
请稍等,以便在您的列表中看到。
require_once 'csrest_subscribers.php';
$name = $_POST['username'];
$email = $_POST['email'];
$phone = $_POST['your-tel'];
$suburb = $_POST['your-suburb'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$wrap = new CS_REST_Subscribers('Your list ID', 'Your API Key');
$result = $wrap->add(array(
'EmailAddress' => $email,
'Name' => $name,
'CustomFields' => array(
array(
'Key' => "Subject",
'Value' => $subject
),
array(
'Key' => "Phone Number",
'Value' => $phone
),
array(
'Key' => "Suburb",
'Value' => $suburb
),
array(
'Key' => "Message",
'Value' => $message
)
),
'Resubscribe' => true
));
echo "Result of POST /api/v3/subscribers/{list id}.{format}'n<br />";
if($result->was_successful()) {
echo "Subscribed with code ".$result->http_status_code;
} else {
echo 'Failed with code '.$result->http_status_code."'n<br /><pre>";
var_dump($result->response);
echo '</pre>';
}
Please does anybody know how to do what i am trying to achieve or know whether this is supported by campaign monitor API or not
根据他们的引用,你应该发送像
这样的东西'CustomFields' => array(
array(
'Key' => 'Field Key 1',
'Value' => 'Value 1'
),
array(
'Key' => 'Field Key 2',
'Value' => 'Value 2'
),
),
但是如果你需要存储一个数组值,我认为你可以通过在你的值中使用序列化的数据来"欺骗"它,然后你可以反序列化返回的数据(当你执行GET)来获得你的数组。