如何使用 (api sendgrid) cakephp 添加列表

How to add a list using (api sendgrid) cakephp

我正在尝试使用 Cake HttpSocket 在外部 Web 服务中发出请求,我正在尝试创建一个新列表我从 api sendgrid

收到错误消息

[正文] => {"errors":[{"message":"request body is invalid"}]}

public function addemail() {
    $HttpSocket = new HttpSocket();
    $lista = array('name' => 'Teste');
    $retorno = $HttpSocket->post('https://api.sendgrid.com/v3/contactdb/lists', $lista,  
    array(
        'header' => array(
            'Content-Type' => 'application/json',
            'Authorization' => 'Bearer SG.XXXXXXXXX'
        )
    ));
    if ($retorno->isOk()) {
        debug($retorno->body());

    }
}

怎么了?在 sendgrid 文档中说 body 应该是这样的

{ "name": "listname" }

您需要 json 像这样对数组进行编码:

$lista = json_encode(array('name' => 'Teste'));