首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >属性在Sendinblue API中无效

属性在Sendinblue API中无效
EN

Stack Overflow用户
提问于 2019-10-28 16:11:22
回答 1查看 3.5K关注 0票数 0

我试图发送带有属性的交易性电子邮件,但是Sendinblue的返回

400坏请求{“代码”:“invalid_parameter”,“消息”:“属性无效”}

在Sendinblue文档中,他们说要使用json对象和set方法。

代码语言:javascript
复制
/**
     * Sets attributes
     *
     * @param object $attributes Pass the set of attributes to customize the template. For example, {\"FNAME\":\"Joe\", \"LNAME\":\"Doe\"}
     *
     * @return $this
     */
    public function setAttributes($attributes)
    {
        $this->container['attributes'] = $attributes;

        return $this;
    }

下面,我的代码发送了一封电子邮件,我用他们的例子:

代码语言:javascript
复制
$templateId = 2; // int | Id of the template
$sendEmail = new \SendinBlue\Client\Model\SendEmail(); // \SendinBlue\Client\Model\SendEmail
$sendEmail->setEmailTo(array('example@mail.com')); //for stackoverflow
$sendEmail->setAttributes('{"LNAME":"John","FNAME":"Doe"}');

try {
    $result = $apiInstance->sendTemplate($templateId, $sendEmail);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AccountApi->getAccount: ', $e->getMessage(), PHP_EOL;
}

我的邮件模板中有我的属性(比如%FNAME%)。

如果我不包括属性,它就能工作.

EN

回答 1

Stack Overflow用户

发布于 2020-11-01 12:55:29

代码语言:javascript
复制
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR API KEY');

$apiInstance = new SendinBlue\Client\Api\TransactionalEmailsApi(
    new GuzzleHttp\Client(),
    $config
);
$templateId = 1;
$sendEmail = new \SendinBlue\Client\Model\SendEmail()
$sendEmail['emailTo'] = array('example@example.com');
$sendEmail['emailCc'] = array('example1@example1.com');
$sendEmail['headers'] = array('Some-Custom-Name' => 'unique-id-1234');
$sendEmail['attributes'] = array('FNAME' => 'Jane', 'LNAME' => 'Doe');
$sendEmail['replyTo'] = 'replyto@domain.com';
$sendEmail['attachmentUrl'] = 'https://example.net/upload-file.pdf';

try {
    $result = $apiInstance->sendTemplate($templateId, $sendEmail);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling TransactionalEmailsApi->sendTemplate: ', $e->getMessage(), PHP_EOL;
}
?>

请试试这个密码。你可以在https://developers.sendinblue.com/reference#sendtemplate-1上找到例子

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58594481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档